Reputation: 285
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
Upvotes: 0
Views: 8259
Reputation: 2191
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:
it
block have something like expect(component.myFunction()).toBe(undefined);
Hope that helps.
Upvotes: 1
Reputation: 276199
How to test if () return; in a function
You don't using spy to determine the inside of the a function. 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.
If you want to know that a particular line return got tested, you need to use coverage reports.
Upvotes: 2