我如何测试我的 if 语句以便它被代码覆盖?
我有这个函数
testing(x) {
if(x == 10) {
return 10;
}
}
,所以我的测试看起来像这样
it('testing function', () => {
expect(component.testing(10)).toBe(10);
})
并且通过了,但问题是当我运行 code-coverage
时,我看到代码覆盖率由于这个 if 语句而减少了 - 所以我不能找到一种方法我该如何测试 这个 if 语句所以 branch
覆盖率就可以了
I have this function
testing(x) {
if(x == 10) {
return 10;
}
}
so my test looks like this
it('testing function', () => {
expect(component.testing(10)).toBe(10);
})
and it passes but the problem is that when i run code-coverage
than i see that code coverage is descresed because of this if statement - so i can't find a way how can i test
this if statement so the branch
coverage will be fine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要测试 x 何时不为 10 才能获得完整的代码覆盖率。
You'll need to test for when x is not 10 to get full code coverage.