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 what code is not covered, but as the app grows and time passes, we'll lose track of this.
Jest comes with a great code coverage tool, so we don't have to keep what is covered in our heads. In this section, we'll use this to discover the code coverage in the project we worked on in the previous section, where we mocked axios:
- Our first task is to add an npm script that will run the tests with the coverage tracking tool switched on. Let's add a new script called test-coverage that includes the --coverage option when react-scripts is executed:
"start": "react-scripts start",
"build": "react-scripts build",