作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为使用 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)
最佳答案
我遇到了几乎相同的问题,但我的案例错误消息是 No element indexed by 55
.
我正在使用 Jest,如果在一个测试中我希望一个对象不具有某些属性,我就会遇到这个错误。
然后我关闭了代码覆盖率,问题消失了,测试通过了。但我不想为此关掉它。
最后对我来说唯一的解决方案变成了改变覆盖提供者在 Jest 配置到 v8 (默认情况下它使用 babel)。
关于javascript - Jest 未能通过 'No element indexed' 的覆盖率报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72491664/
我是一名优秀的程序员,十分优秀!