【问题标题】:AngularJS Directives - unit tests Karma coverageAngularJS 指令 - 单元测试业力覆盖率
【发布时间】:2015-11-15 03:02:39
【问题描述】:
【问题讨论】:
标签:
angularjs
unit-testing
karma-jasmine
karma-coverage
【解决方案1】:
您看不到指令代码覆盖率的原因是,您提到的链接使用了 $compile() 和 beforeEach() 通过 compileDirective() 函数调用的 $digest() 。
将那段代码(进入 compileDirective 的代码)移到您的 it() 中,它应该对指令进行覆盖。
代替
describe("do some directive testing",function(){
beforeEach(function(){
compileDirective();
});
it('your test code',function(){
//some code here
});
执行以下操作。
describe("do some directive testing",function(){
beforeEach(function(){
// some other code which execute before each of the it()..
});
it('your test code',function(){
compileDirective();
//some code here
});
所以基本上你可能需要对你的代码做一些调整。
【解决方案2】:
我在 Grunt 配置文件中发现了一些问题,这就是覆盖范围没有更新的原因。所以,Julien Bouquillon 的例子非常好,我推荐它。