【发布时间】: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
我正在尝试测试最终调用 GetRole 函数的 SetRole 函数,但我无法覆盖代码覆盖率。请指导我测试级联函数,嵌套函数,函数中的函数。
component.ts
SetRole(inp){
this.role = inp;
this.GetRole()
}
【问题讨论】:
标签: angular unit-testing jestjs karma-jasmine angular-unit-test
试试这个:
it('SetRole',() => {
const inp = 'dummyInput';
const spy = spyOn(component,'GetRole')
component.SetRole(inp)
expect(spy).toHaveBeenCalled()
});
【讨论】: