gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 786 forks source link

Istanbul doesn't ignore nested if, when not executed #948

Open danziamo opened 2 years ago

danziamo commented 2 years ago

Hello,

const wrongbranch = () => {
  const a = 2;
  if (a === 1) {
    console.log("test");
    /* istanbul ignore if */
    if (a === 3) {
      console.log("another test")
    }
  }
  return 3;
}

Saying that second if path is not taken, even though first if was not executed

However when ignore if is replaced with ignore next it displays properly and calculates branches properly

const wrongbranch = () => {
  const a = 2;
  if (a === 1) {
    console.log("test");
    /* istanbul ignore next */
    if (a === 3) {
      console.log("another test")
    }
  }
  return 3;
}

Is this a bug? or it is supposed to be like that?

Thank you.