【问题标题】:Code Coverage issue in angular 8 with function properties具有函数属性的 Angular 8 中的代码覆盖率问题
【发布时间】:2020-09-08 09:04:33
【问题描述】:

谁能建议 Jasmine 的单元测试用例来解决这个代码覆盖率问题?

【问题讨论】:

    标签: javascript angular typescript jasmine karma-jasmine


    【解决方案1】:
    1. 您需要创建一个describe 块,如下所示:

      it('should create with necessary variables', () => {
        expect(component).toBeTruthy();
        component.Items[0].getInfo();
        expect(component.isIndian).toBeTruthy();
        // and so on....
      });
      
    2. 您在第 19 行将 this.isIndian 设置为 false,然后在第 21 行设置为 true。请相应更正。

    如果您想探索最佳实践,可以查看文章集合in this article。

    【讨论】:

    • 我同意作为图像提供的代码通常不是最佳的。但是在这种情况下,我认为 OP 想要说明红色代码渲染,我猜这表示未覆盖的代码。
    • @halfer 非常感谢。当然,我会相应地更改 isIndian 属性。错误地未注释属性。
    • @Shashank Vivek 非常感谢。
    猜你喜欢
    • 2018-05-08
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多