Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 表单域上的Jasmine Karma单元测试_Angularjs_Unit Testing_Karma Jasmine_Jasmine Jquery - Fatal编程技术网

Angularjs 表单域上的Jasmine Karma单元测试

Angularjs 表单域上的Jasmine Karma单元测试,angularjs,unit-testing,karma-jasmine,jasmine-jquery,Angularjs,Unit Testing,Karma Jasmine,Jasmine Jquery,我想在不使用量角器的情况下为用户名、电子邮件验证和提交按钮单击编写单元测试用例。有可能吗??如果没有,那么我可以用什么其他方法在它们上面编写测试用例呢 我的参考表格: <form class="elegant-aero" name="sampleForm" novalidate> <p> <label>Username:</label> <input type="text" class="form-c

我想在不使用量角器的情况下为用户名、电子邮件验证和提交按钮单击编写单元测试用例。有可能吗??如果没有,那么我可以用什么其他方法在它们上面编写测试用例呢

我的参考表格:

  <form  class="elegant-aero" name="sampleForm" novalidate>
  <p>
        <label>Username:</label>
        <input type="text" class="form-control" name="username" ng-model="username" required >
        <span ng-show="sampleForm.username.$error.required">Username is required.</span>
    </p>
    <p>
        <label>Email:</label>
        <input type="email" class="form-control" name="email" ng-model="email" required>
        <span ng-show="sampleForm.email.$error.required">Email is required.</span>
        <span ng-show="sampleForm.email.$error.email">Invalid email address.</span>
    </p>
    <p>
        <button class="btn btn-link" ng-click="reset()">Reset</button>
        <input type="submit" class="btn btn-primary" ng-disabled="sampleForm.$invalid" ng-click="checkData()">
    </p>
  </form>
请帮助我,因为我刚刚接触茉莉花业力,刚刚开始学习


提前感谢。

量角器是自然的解决方案

Karma和Jasmine用于“单元测试”

换句话说,测试您的控制器或其他独立于前端的东西

然而,如果你想要一个非自然的解决方案,那么人们有时会在karma配置中预加载html,并与angulars compile结合使用,但它会变得很混乱

   $scope.reset = function(){

        $scope.username = "";
        $scope.email = "";
   }   

app.controller("myCtrl", function($scope, $http) {
   $scope.checkData = function() {

        if ($scope.username != validUsername || $scope.email != validEmail) {
            alert("The data provided do not match with the default owner");
        } else {
            alert("Seems to be ok!");
        }
    }

});