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

154
Visualizações
How can adding a test case decrease code coverage in Jest?

I just ran into a strange situation with a Jest test suite. I did not modify the code, but I added a test.

Before:

 mylibrary.js |   95.65 |    89.66 |     100 |   95.65 | 54-56,84       
---------------|---------|----------|---------|---------|-------------------
Test Suites: 3 passed, 3 total
Tests:       22 passed, 22 total

After:

 mylibrary.js |   95.65 |    89.29 |     100 |   95.65 | 54-56,84          
---------------|---------|----------|---------|---------|-------------------
Test Suites: 3 passed, 3 total
Tests:       23 passed, 23 total

I'm not able to share the code, but I want to ask: how is it possible that in Jest the test coverage would decrease when I am adding a test call?

The result I was expecting was an increase of 2 lines of coverage.

Using Jest 27.1.0. It's a pretty simple library with no dependencies.

(I have re-added/removed the test case to verify this isn't some weirdness caused by some other factor).

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

0

Your statements, functions, and lines look identical, while your branch has decreased slightly. Looks like your new test has covered only one scenario of some branching logic, while not testing the alternate scenarios for the logic.

In general, it is possible to add tests and have the coverage decrease by either not covering all of the statements, functions, lines or branch paths. In this case it looks like your added test did not cover all the branch paths.

Check the Uncovered Line #s column for a line number that is colored yellow.

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