Muh*_*rif 11 javascript unit-testing jestjs
我是测试新手。我在测试中遇到问题。我的测试在第一次不匹配后立即退出,并且不检查剩余的期望
我想开玩笑地完成每个期望的测试,即使它发生错误或意外的值
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);
Run Code Online (Sandbox Code Playgroud)
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)`
Run Code Online (Sandbox Code Playgroud)
它在第 50 行没有显示错误(顺便说一句,48、49 之间的值是正确的)。
Jest 将在一个断言失败后终止。这是为了支持测试应该准确断言一件事的想法。在单个测试中具有多个相关断言不一定是坏事,但如果您的单元测试测试单个功能并且一个断言失败,那么其他断言是否正确并不重要。如果您需要找出测试结果出了什么问题,只需 debug 或 console.log concreteScopes 即可。