Getting code coverage
Code coverage is how we refer to how much of our app code is covered by unit tests. As we write our unit tests, we’ll have a fair idea of what code is covered and not covered, but as the app grows and time passes, we’ll lose track of this.
In this section, we’ll learn how to use Jest’s code coverage option so that we don’t have to keep what is covered in our heads. We will use the code coverage option to determine the code coverage on the checklist component and understand all the different statistics in the report. We will use the code coverage report to find some uncovered code in our checklist component. We will then extend the tests on the checklist component to achieve full code coverage.
Running code coverage
To get code coverage, we run the test
command with a --coverage
option. We also include a --watchAll=false
option that tells Jest not to run in watch mode. So, run the following command in a terminal...