Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

884
Visualizações
Jest fails coverage reports with 'No element indexed'

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.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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).

about 4 years ago · Juan Pablo Isaza Relatório

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda