[英]Angular Jasmine How to test if () return; in a function
I intent to test a function as below: 我打算测试以下功能:
myFunction(input) {
if (...) {
return;
} else {
do something
}
}
How to test the condition is return? 如何测试条件是否退货?
it('should', async(() => {
spyOn(component, 'myFunction')
// ????
}));
Thank you 谢谢
How to test if () return;
如何测试()是否返回; in a function
在功能上
You don't using spy to determine the inside of the a function. 您无需使用间谍来确定a函数的内部。 You spy on arguments and return values.
您监视参数并返回值。 You can use spy on to determine if the function returns
undefined
(the implicit value for return;
) for a given input. 您可以使用spy on来确定函数是否为给定的输入返回
undefined
的值( return;
的隐式值)。
If you want to know that a particular line return got tested, you need to use coverage reports. 如果您想知道特定线路的退货已经过测试,则需要使用覆盖率报告。
Without actual code it's hard to write a code sample for you to use. 没有实际的代码,很难编写供您使用的代码示例。 If you want to test the return of the function of the
if
part the logic will be something like this: 如果要测试
if
部分功能的返回,则逻辑将是这样的:
it
block have something like expect(component.myFunction()).toBe(undefined);
it
块中,有一个类似于expect(component.myFunction()).toBe(undefined);
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.