23
votes

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

3

3 Answers

31
votes

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

0
votes

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'.

0
votes

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);
}