How to ignore branch coverage for missing 'else'
Asked Answered
P

3

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

Patroclus answered 7/8, 2015 at 17:18 Comment(0)
P
40

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

Pitt answered 20/8, 2015 at 5:31 Comment(0)
B
7

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);
}
Bridgid answered 17/8, 2021 at 16:31 Comment(2)
How to do this for each file, is there any global setting available?Misinform
Same question for me.Infiltration
L
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'.

Luiseluiza answered 16/8, 2016 at 21:1 Comment(1)
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 itBonacci

© 2022 - 2024 — McMap. All rights reserved.