gpt4 book ai didi

javascript - Jest 未能通过 'No element indexed' 的覆盖率报告

转载 作者:行者123 更新时间:2023-12-05 00:28:42 26 4
gpt4 key购买 nike

我正在为使用 Redux Toolkit 的 Next.js 应用程序运行 jest 测试套件。我正在使用 msw 模拟对 Redux Toolkit 处理的 Next 应用程序之外的另一个 api 的任何必要调用。
我没有模拟所有的 RTK 查询端点,只有我目前在测试中使用的那些。

当我通过 npm run test 在没有覆盖生成的情况下运行时,测试运行良好.
但是,当我通过 npm run test -- --coverage 运行覆盖率报告时,所有测试都失败并且它们都有相同的错误:

- Test suite failed to run

No element indexed by 9

at ArraySet_at [as at] (node_modules/source-map-support/node_modules/source-map/lib/array-set.js:109:9)
at BasicSourceMapConsumer.SourceMapConsumer_originalPositionFor [as originalPositionFor] (node_modules/source-map-support/node_modules/source-map/lib/source-map-consumer.js:673:30)
at mapSourcePosition (node_modules/source-map-support/source-map-support.js:214:42)
at wrapCallSite (node_modules/source-map-support/source-map-support.js:358:20)
at node_modules/source-map-support/source-map-support.js:399:26
at Array.map (<anonymous>)
at Function.prepareStackTrace (node_modules/source-map-support/source-map-support.js:398:30)

我发现如果我将 msw 处理程序设置为空数组,则不会出现错误。正如预期的那样,少数需要 API 的测试失败了。但是,否则测试都运行良好。
我不确定从这里去哪里。任何意见是极大的赞赏。

最佳答案

我遇到了几乎相同的问题,但我的案例错误消息是 No element indexed by 55 .
我正在使用 Jest,如果在一个测试中我希望一个对象不具有某些属性,我就会遇到这个错误。
然后我关闭了代码覆盖率,问题消失了,测试通过了。但我不想为此关掉它。
最后对我来说唯一的解决方案变成了改变覆盖提供者在 Jest 配置到 v8 (默认情况下它使用 babel)。

关于javascript - Jest 未能通过 'No element indexed' 的覆盖率报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72491664/

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