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 787 forks source link

Ignore if without else #915

Open vldwbx opened 5 years ago

vldwbx commented 5 years ago

I am doing code coverage of an app running live and need to ignore some guard conditions that never are covered when app is running live. I tried all options below and still have red flag near my if statement:

1: Ignore if and else in one tag

/* istanbul ignore if|else */
if (A) {
      throw new Error("..null or undefined.");
}

2: Ignore if and else in two tags

/* istanbul ignore if */
/* istanbul ignore else */
if (A) {
      throw new Error("..null or undefined.");
}

3: Ignore else, then ignore code inside if with 'next':

/* istanbul ignore else */
if (A) {
      /* istanbul ignore next */
      throw new Error("..null or undefined.");
}

4: Ignore if:

/* istanbul ignore if */
if (A) {
      throw new Error("..null or undefined.");
}

5: Ignore with multiple next's:

/* istanbul ignore next */
if (A) {
      /* istanbul ignore next */
      throw new Error("..null or undefined.");
}