在一个角度指令中,我有这样的代码:
$('[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单元测试中进行处理?
发布于 2014-03-21 12:45:48
同样的问题,但我做了一个解决办法,通过点击提交按钮。
bootstrapInput.find('input[type="submit"]').click();
expect(bootstrapInput.children().hasClass('has-error')).toBe(true);希望有人能对此找到解释。
https://stackoverflow.com/questions/20565968
复制相似问题