伊斯坦布尔如何忽略ES6的默认值分支(babel编译为ES5)

问题描述 投票:13回答:2

在ES5中,我们可以这样写:

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

怎么忽略在ES6?

function(a = 123 ){

}

我试过这个:

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

}

但它不起作用。

ecmascript-6 code-coverage babeljs istanbul
2个回答
2
投票

这对我有用:

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

}

0
投票

使用TypeScript时,这有点难以解决,因为类型必须匹配。我能够通过为每个参数传递undefined来使其工作。例如...

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);
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.