c8 icon indicating copy to clipboard operation
c8 copied to clipboard

Implicit `else` clause is not considered in coverage.

Open mikeal opened this issue 4 years ago • 2 comments

Consider the code below.

const x = 'asdf'
const fn = y => {
  if (typeof y !== 'object') {
    y = 'yup'
  }
  console.log(y)
}
fn(x)

The code branches on the if statement and the behavior changes if it’s false, but there isn’t an explicit else clause.

When running nyc this correctly says that only 50% of the branch coverage was detected, but in c8 it reports that 100% of the branch coverage was covered. The output can be found in this gist.

mikeal avatar Jun 12 '20 15:06 mikeal