After we updated our unit tests to cover the missed catch block, our Statements coverage is now 100%. However, if we examine our code, we'll find two modules that still lack unit tests:
- validate: User validation function at src/validators/users/create.js
- injectHandlerDependencies: Utility function at src/utils/inject-handler-dependencies.js
They did not show up in the coverage report because the unit tests never imported those files. But do we need to write unit tests for every unit? To answer this question, you should ask yourself – "Do I have confidence that this block of code works?" If the answer is "yes", then writing additional tests may be unnecessary.
Code coverage for a unit should not be analyzed based on unit tests alone, since there may be integration and E2E tests that use that unit. If these other tests cover what the unit tests don't, and the tests are passing, then that should give you confidence that your unit is working as intended.
Therefore, a more useful metric is to analyze the code coverage of all tests, not just unit tests.