【问题标题】:AngularJS Directives - unit tests Karma coverageAngularJS 指令 - 单元测试业力覆盖率
【发布时间】:2015-11-15 03:02:39
【问题描述】:

我在涉及指令单元测试时遇到问题。我使用的方式来自: http://blog.revolunet.com/blog/2013/12/05/unit-testing-angularjs-directive/(朱利安·布奎隆) 为我的指令创建单元测试。该博客上提出的想法看起来非常适合我的需求并且得到了很好的解释,但我的问题是覆盖率没有反映在 Karma Coverage(伊斯坦布尔代码覆盖率工具)中。

我应该如何创建指令单元测试以反映在覆盖率摘要中?有人可以举个例子吗?

【问题讨论】:

    标签: 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 的例子非常好,我推荐它。

      【讨论】:

        猜你喜欢
        • 2016-06-19
        • 1970-01-01
        • 2016-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-18
        • 2015-10-06
        • 1970-01-01
        相关资源
        最近更新 更多