Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!