【发布时间】:2013-12-13 11:58:46
【问题描述】:
在一个角度指令中,我有以下代码:
$('[name=' + formName + ']').bind('submit', function () {
validate();
});
在 Karma 测试的 beforeEach 子句中,我有以下代码:
bootstrapInput = $compile('<form novalidate name="aForm">' +
'<input-field icon="true" for="email">' +
'<div>' +
'<input class="form-control" class="email" name="email" id="email" type="email" ng-model="user.email" required />' +
'</div>' +
'<input-validation for="email" custom-error="custom error" required="Email is required" email="Email must be in valid format"/>' +
'</input-field>' +
'<button type="submit" value="valider" ></button>' +
'</form>')($rootScope);
在我的单元测试中,我有这个代码:
it('should launch validation process if form has just been submitted', function(){
bootstrapInput.submit(); //way of doing?
expect(bootstrapInput.children().hasClass('has-error')).toBe(true);
});
但我收到以下错误:
Some of your tests did a full page reload!
问题是:如何在 Karma 单元测试中触发提交事件以进行处理,而不需要重新加载页面?
【问题讨论】:
-
你为什么不直接使用
ng-submit?
标签: angularjs angularjs-directive karma-runner