3
我想寫單元測試用例的用戶名,電子郵件驗證和提交按鈕點擊而不使用量角器。是否有可能這樣做?如果不是的話,那麼我可以通過其他方式編寫測試用例。茉莉花Karma單元測試表單域
我的參考形式:
<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>
控制器js文件供參考:
VAR validUsername = 「Thodoris白族」; var validEmail =「[email protected]」;
$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!");
}
}
});
請幫忙,因爲我是茉莉花業的新手,剛開始學習。
在此先感謝。
非常感謝你....... – Ziva