Javascript 使用test.each时跳过一些测试
我使用test.each来运行函数的一些输入数据组合:Javascript 使用test.each时跳过一些测试,javascript,jestjs,Javascript,Jestjs,我使用test.each来运行函数的一些输入数据组合: const组合=[ [0,0], [1,0],//此组合无效,我想跳过它 [0,1], [1,0], [1,1], ] 描述('测试所有组合',()=>{ 测试。每个(组合)( “组合a=%p和组合b=%p有效”, (a、b、done)=>{ 期望(foo(a,b),toEqual(bar)) }); }); 现在,其中一些组合目前不起作用,我想暂时跳过这些测试。如果我只有一个测试,我只需执行测试。跳过,但如果我想跳过输入数组中的某些特定
const组合=[
[0,0],
[1,0],//此组合无效,我想跳过它
[0,1],
[1,0],
[1,1],
]
描述('测试所有组合',()=>{
测试。每个(组合)(
“组合a=%p和组合b=%p有效”,
(a、b、done)=>{
期望(foo(a,b),toEqual(bar))
});
});
现在,其中一些组合目前不起作用,我想暂时跳过这些测试。如果我只有一个测试,我只需执行
测试。跳过,但如果我想跳过输入数组中的某些特定值,我不知道这是如何工作的。不幸的是,jest不支持跳过组合元素的注释。你可以这样做,用一个简单的函数过滤掉你不想要的元素(我很快就写了一个,你可以改进它)
const combinations = [
[0,0],
[1,0], // this combination doesn't work, I want to skip it
[0,1],
[1,0],
[1,1],
]
const skip = [[1,0]];
const combinationsToTest = combinations.filter(item =>
!skip.some(skipCombo =>
skipCombo.every( (a,i) => a === item[i])
)
)
describe('test all combinations', () => {
test.each(combinationsToTest)(
'combination a=%p and b=%p works',
(a,b,done) => {
expect(foo(a,b).toEqual(bar))
});
});