admin管理员组文章数量:1323157
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.
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.
Share edited Jun 8, 2022 at 10:02 Liam 29.8k28 gold badges138 silver badges202 bronze badges asked Jun 3, 2022 at 15:11 GurnzbotGurnzbot 4,1528 gold badges41 silver badges57 bronze badges2 Answers
Reset to default 5This 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:
npm install --save-dev babel-jest @babel/core @babel/preset-env
Source
which should make the above error go away.
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).
本文标签: javascriptJest fails coverage reports with 39No element indexed39Stack Overflow
版权声明:本文标题:javascript - Jest fails coverage reports with 'No element indexed' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742142630a2422650.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论