【问题标题】:How to unit test nested functions in angular using jasmine-karna如何使用 jasmine-karna 对 Angular 中的嵌套函数进行单元测试
【发布时间】:2021-09-29 22:47:26
【问题描述】:

我正在尝试测试最终调用 GetRole 函数的 SetRole 函数,但我无法覆盖代码覆盖率。请指导我测试级联函数,嵌套函数,函数中的函数。

component.ts

SetRole(inp){
this.role = inp;
this.GetRole()
}

【问题讨论】:

    标签: angular unit-testing jestjs karma-jasmine angular-unit-test


    【解决方案1】:

    试试这个:

        it('SetRole',() => {
        
        const inp = 'dummyInput';
        const spy = spyOn(component,'GetRole')
        component.SetRole(inp)
        
        expect(spy).toHaveBeenCalled()
    });
    

    【讨论】:

      猜你喜欢
      • 2021-12-10
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      相关资源
      最近更新 更多