[英]Skip some tests when using test.each in jest
我正在使用 test.each 來運行 function 的一些輸入數據組合:
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
,但如果我想跳過輸入數組中的某些特定值,我不知道這是如何工作的。
不幸的是,jest 不支持跳過組合元素的注釋。 你可以做這樣的事情,你可以使用簡單的 function 過濾掉你不想要的元素(我寫得很快,你可以改進它)
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))
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.