JEST失败的覆盖范围报告没有'没有元素索引'
我正在使用使用Redux Toolkit的Next.js应用程序运行Jest Test Suites。我正在使用MSW嘲笑由Redux Toolkit处理的下一个应用程序之外其他API的任何必要的呼叫。
我还没有嘲笑所有RTK查询端点,只有我当前在测试中使用的端点。
当我通过NPM运行测试
运行时运行时,测试正常运行。
但是,当我通过npm运行测试进行覆盖范围报告-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失败的少数测试。但是,测试否则运行良好。
我不确定从这里去哪里。任何建议都非常感谢。
I am running jest test suites for a Next.js app that uses Redux Toolkit. I'm using msw to mock any necessary calls to another api outside of the Next app that are handled by Redux Toolkit.
I have not mocked ALL of the RTK query endpoints, only the ones which I am currently using in my tests.
The tests run fine when I'm running without coverage generation via npm run test
.
However, when I run with coverage reports via npm run test -- --coverage
, all tests fail and they all have the same error:
- 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)
I found that if I set the msw handlers to an empty array, the error doesn't appear. The few tests which require the API fail, as expected. However, the tests all run fine otherwise.
I'm unsure where to go from here. Any advice is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在应该解决此
错误开玩笑到最新版本。
似乎这个问题与将Babel用作代码覆盖提供商的玩笑有关。这就是为什么切换到
v8
在上工作。如果您不想使用V8(当前标记为实验)。然后,您需要将Babel安装到您的构建中:
source
上面的错误消失了。
This bug should now be fixed
If your still having this problem, upgrade Jest to the latest version.
It seems this issue is to do with jests use of babel as the code coverage provider. Which is why switching to
v8
works around this issue.If you don't want to use v8 (this is marked as experimental currently). Then you will need to install babel into your build:
Source
which should make the above error go away.
我遇到了几乎相同的问题,但是我的情况错误消息是
没有由55
索引的元素。我正在使用开玩笑,如果在一个测试中,我希望一个对象没有某些属性,我会遇到此错误。
然后我关闭了代码覆盖范围,问题消失了,测试通过了。但是我不想为此关闭它。
最后,对我来说,唯一的解决方案变成了 CoverageProvider 在Jest Config到 v8 (默认情况下,它使用babel)。
I had almost the same issue, but I my case error message was
No element indexed by 55
.I am using Jest, and in case when in one test I expect an object not to have certain property, I've got this error.
Then I turned off code coverage and the problem disappeared and tests were passed. But I didn't want to turn it off for that.
Finally the only solution for me became changing coverageProvider in jest config to v8 (by default it uses babel).