douglasduteil/isparta

Else path not taken

Opened this issue · 1 comments

Hello

I ran into a weird issue: when I have the following setup,

if(!array.length) {
  return null;
}

return doSomething();

It reported that else path is not taken:
epnt1

I am testing the else part too, by asserting doSomething is called. I refactored the code to the following:

if(!array.length) {
  return null;
} else {
  return doSomething();
}

which ended up with following report:
epnt2

Once again I refactored the code:

let returnValue;

if(!array.length) {
  returnValue = null;
} else {
  returnValue = doSomething();
}

return returnValue;

which resulted in 100% coverage. Can I please know what is wrong with first or second code pattern? why would it say that the else path was not taken, even though there are 'hits' on those lines of code? is this a bug or by design? Though I can somewhat digest the first one, I would say the second one is a real bug!

(I have cut many things inside the braces in the images to simplify stuff, the code given is the (pseudo)real one)

Same thing happens in nyc which IIRC uses the same core.