javascript - 如何在将测试声明为“失败”之前多次重试 chaijs 预期断言
问题描述
我没有使用 Mocha 作为我的测试运行程序,我使用的是 cucumberJs。有没有办法在声明步骤失败之前仅重新运行预期条件给定次数?
假设一个简单(但不现实)的步骤是:
Given(/^I want to check the username to be John$/, (name: string)=>{
expect(name).to.be.equals('John');
});
现在,如果名字是 Sam,expect 条件将失败。但是,我想在声明它失败之前运行期望条件至少 5 次。是否有任何 chaijs 配置/插件可以实现相同的功能?
任何帮助将不胜感激。
解决方案
据我所知,Chai 没有任何此类功能。看起来MochaJS确实有一些东西可以实现这一点。如果您仍想使用 chai,这是可行的。
Given(/^I want to check the username to be John$/, (name: string) => {
let retry = 3;
for (let index = 0; index < retry; index++) {
try {
expect(name).to.be.equals('John');
index = retry + 1;
} catch (error) {
console.log(index);
if (index == retry - 1) throw new Error('Failed')
}
}
});
推荐阅读
- java - 如何为视频视图制作自定义媒体控制器
- c# - 错误 CS0019:运算符“<”不能应用于“字符串”和“整数”类型的操作数
- typescript - TypeScript:类型“数字”不可分配给类型“0”
- java - 带有管道的 Shell 脚本无法在 Linux 上使用 java Runtime Process 执行
- ios - CupertinoTextField 中的 Flutter 文本验证
- shopware - 如何扩展 shopware.api.customergroup
- json - 如何在 MongoDB 集合中插入以下 JSON 作为不同的文档
- node.js - 如何使用 NodeJs 实现红帽流程自动化管理器(RHPAM)
- javascript - 哪些数据结构可以用作 Map 键?
- php - Apache 服务器上的反向代理,无需访问配置文件