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