gpt4 book ai didi

javascript - 即使在错误之后继续检查expect()也是开 Jest

转载 作者:行者123 更新时间:2023-12-02 23:18:21 24 4
gpt4 key购买 nike

我是测试新手。我在测试中遇到问题。我的测试在第一次不匹配后立即退出,并且不检查剩余的期望

我想 Jest 完成每个期望的测试,即使它发生错误或意外的值

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 将在一次断言失败后终止。这是为了支持 a test should assert exactly one thing 的想法。在单个测试中具有多个相关断言不一定是坏事,但如果您的单元测试测试单个功能并且一个断言失败,那么其他断言是否正确并不重要。如果您需要找出测试结果出了什么问题,只需 debug 或 console.logcreteScopes。

关于javascript - 即使在错误之后继续检查expect()也是开 Jest ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57065326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com