我已经创建了一个编辑指令来将html输入包装在一个奇特的框架中.
现在我正在创建一个单元测试来检查一旦输入输入,就会设置表单控制器的脏状态.
这是我到目前为止所得到的,但它在第二次预期失败了.
这有什么不对?
提前致谢!
describe('dirty',function () { it('false',function () { var scope = $rootScope.$new(),form = $compile('<form name="form"><edit ng-model="model"></edit></form>')(scope),input = form.find('input'); scope.$digest(); expect(scope.form.$dirty).toBeFalsy(); input.triggerHandler('keydown',{ which: 65 }); expect(scope.form.$dirty).toBeTruthy(); }); });
编辑:
对于所有重要的事情,它归结为这个plunker(没有jQuery)…或this使用jQuery
任何的想法?
解决方法
ngKeySpec.js中的角度单位测试很有帮助:
it('should get called on a keydown',inject(function($rootScope,$compile) { element = $compile('<input ng-keydown="touched = true">')($rootScope); $rootScope.$digest(); expect($rootScope.touched).toBeFalsy(); browserTrigger(element,'keydown'); expect($rootScope.touched).toEqual(true); }));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。