javascript - 开玩笑说即使在出错后也继续检查 expect()
问题描述
我是测试的新手。我在测试中遇到问题。我的测试在第一次不匹配后立即退出,并且不检查剩余的期望
我想开玩笑地完成对每个期望的测试,即使它发生错误或意外值
test("concrete scope test should pass", async () => {
const scale = funcs.getScale(theJson);
const concreteScopes = await s.getConcreteScope(
theJson,
lines,
scale,
data.scopeId,
order.pdf
);
expect(concreteScopes.ScopeId).toBe(33);
expect(concreteScopes.Name).toEqual(theJson.Name);
expect(concreteScopes.Address).toEqual(theJson.Address);
expect(concreteScopes.PDF).toEqual("dfa");
}, 300000);
我在第一个期望expect(concreteScopes.ScopeId).toBe(33);
和最后一个期望中有错误expect(concreteScopes.PDF).toEqual("dfa");
但它在第一个错误时终止并且没有显示剩余的错误
expect(received).toBe(expected) // Object.is equality
Expected: 33
Received: "275188"
45 | order.pdf
46 | );
> 47 | expect(concreteScopes.ScopeId).toBe(33);
| ^
48 | expect(concreteScopes.Name).toEqual(theJson.Name);
49 | expect(concreteScopes.Address).toEqual(theJson.Address);
50 | expect(concreteScopes.PDF).toEqual("dfa");
at Object.toBe (__test__/concretescope.test.js:47:34)`
它在第 50 行没有显示错误(顺便说一句,48、49 之间的值是正确的)。
解决方案
Jest 将在一个断言失败后终止。这是为了支持测试应该准确断言一件事的想法。在一个测试中拥有多个相关的断言并不一定是坏事,但是如果你的单元测试测试一个单一的功能并且一个断言失败,那么其他的是否正确并不重要。如果您需要弄清楚您的测试结果出了什么问题,只需调试或 console.log 具体范围。
推荐阅读
- python - 如何在 Django 模板的 for 循环中使用 2dicts?
- javascript - Django/jQuery-从多个按钮获取提交按钮值
- seo - 链接不同页面中的模式标记
- php - 如果按 sql php 排序
- java - Android 跳过了 602 帧!应用程序可能在其主线程上做了太多工作
- amazon-web-services - CloudFormation 创建更改集失败,并显示“模板参数由转换修改”
- java - 如何通过可变参数(程序参数)有条件地排除 Spring bean?
- python - 将 DataArray 插值到新坐标
- python - 如何使用 Xpath 为 selenium 选择锚标记?
- mocha.js - Mochawesome 报告未在浏览器中打开?