Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Istanbul how to ignore default value branch for ES6 (babel compiles to ES5)

In ES5 we can write like this:

function(a){
  /* istanbul ignore next */
  a = a || 123;
}

how to ignore In ES6?

function(a = 123 ){

}

I tried this:

function(/* istanbul ignore next */a = 123 ){

}

but it's not working.

like image 767
Sabrina Luo Avatar asked Apr 29 '16 04:04

Sabrina Luo


2 Answers

This works for me:

function(
  /* istanbul ignore next */
  a = 123
){

}
like image 82
jesset Avatar answered Sep 21 '22 08:09

jesset


When using TypeScript, this was a bit harder to solve since the types must match. I was able to get it to work by passing in undefined for each parameter. For example...

function testMe(a:SomeType = { foo: 'bar' }, b:AnotherType = { bar: 'baz'}) {
  return a * b;
}
describe('Branch Coverage', () => {
  it('should pass branch coverage', () => {
    expect(testMe(undefined, undefined);
  });
});
like image 28
bmarti44 Avatar answered Sep 22 '22 08:09

bmarti44