26

Is it possible to ignore the marker E in istanbul branch coverage?

I am using Jasmine+karma+Istanbul. Is there any possibility to ingore E and get 100% branch coverage?

Maybe a property that can be set in config?

Here is an example of the coverage results example of the error

Artur Grigio
  • 5,185
  • 8
  • 45
  • 65
rajesh madaswamy
  • 359
  • 1
  • 4
  • 11

3 Answers3

39

You can use /* istanbul ignore else*/ just before the if statement to ignore the missing else.

Hawken MacKay Rives
  • 1,171
  • 1
  • 16
  • 26
Anobika
  • 453
  • 3
  • 6
6

You can use /* istanbul ignore else */ to tell istanbul not to include that in the coverage.

/* istanbul ignore else */
if (props.onChange) {
    props.onChange(event);
}
Manish Jangir
  • 5,329
  • 4
  • 42
  • 75
0

If you don't want the comments all over the place you can also set up another test where you actually hit that else.

If you have something like this:

_method: function () {
  if (this.foo === 'foo') {
    this.bar = false
  }
}

You just need to create a test where this.foo does not equal 'foo'.

Bill Criswell
  • 32,161
  • 7
  • 75
  • 66
  • yes, thanks.. but in some cases it's seems difficult to create a test ( i.e. promise catch(e) ..if { validation error.. } else { next(e) }. the else block is picking up any other kind of error and passing them to the next middleware error handler... appreciate any link to it –  Jun 25 '17 at 07:30