javascript - 开玩笑地使用 test.each 时跳过一些测试
问题描述
我正在使用 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
,但如果我想跳过输入数组中的一些特定值,我不知道这是如何工作的。
解决方案
不幸的是,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))
});
});
推荐阅读
- soap - Websphere 应用服务器禁用跨节点的会话持久性
- python - 从数据框中提取文本特征并将它们与其他类型的特征(异构数据)一起用于 sklearn 目的:TypeError
- c# - 如何更新 DataGridView 中的倒数计时器?
- vega-lite - Vega-lite 交互式图例和条形图
- google-cloud-platform - Google Cloud Load Balancer - 子域重定向到存储桶中的特定文件夹
- python - 检查一个字符串在Django中是否有大写字母?
- ios - Swift - 如何从 REST API 解码 json
- excel - Excel:保存 Excel 文件后未更新结构化表引用
- python - 如何解决mysql中的连接错误
- excel - 尝试从 TFS 查询创建电子表格时出错