I have a index.js which looks like
...
[line 69] if A:
[line 70] foo()
[line 71] else if B:
[line 72] bar()
I have written a test for line 69 - 70, the evidence is if I comment it out, the yarn test --coverage will show line 69, 70 missing.
However, even with this test, the coverage complains line 69 is missing
Another thing I noticed is that if I swap the if conditions to
...
[line 69] if B:
[line 70] bar()
[line 71] else if A:
[line 72] foo()
It is still line 69 missing in coverage
What is the reason for this in jest? How can I fix that?
There are really three branches here: either if
gets triggered, or else if
, or neither.
Even though the latter case is empty in this case (as there is no else
statement) you still need a test where neither if
or else if
gets triggered for full coverage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With