在ES5中,我们可以这样写:
function(a){
/* istanbul ignore next */
a = a || 123;
}
怎么忽略在ES6?
function(a = 123 ){
}
我试过这个:
function(/* istanbul ignore next */a = 123 ){
}
但它不起作用。
这对我有用:
function(
/* istanbul ignore next */
a = 123
){
}
使用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);
});
});