Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda