使用test.each开玩笑时跳过一些测试

问题描述 投票:0回答:1

我正在使用test.each来运行功能的输入数据的某些组合:

const combinations = [
  [0,0],
  [1,0], // this combination doesn't work, I want to skip it
  [0,1],
  [1,0],
  [1,1],
]

describe('test all combinations', () => {
  test.each(combinations)(
    'combination a=%p and b=%p works',
    (a,b,done) => {
      expect(foo(a,b).toEqual(bar))
  });
});

现在,这些组合中的某些目前不起作用,我暂时想跳过这些测试。如果仅进行一项测试,我只会做test.skip,但是如果我想跳过输入数组中的某些特定值,我不知道这是如何工作的。

javascript jest
1个回答
1
投票

很遗憾,笑话不支持用于跳过组合元素的注释。您可以执行类似的操作,在此您可以使用一个简单的函数过滤掉不需要的元素(我写的很快,您可以对其进行改进)

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