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!");
}
}
});