Step 12

You can also generate code coverage! Your tests code coverage is what percentage of the code is currently covered by your tests.

Update the jest.config.js file:

  module.exports = {
    preset: "@shelf/jest-mongodb",
    verbose: true,
+   collectCoverage: true,
+   coverageDirectory: "coverage",
  };

Rerun the tests. Jest must create a coverage folder at the root of your repository.

Make sure to add coverage to .gitignore so it is not pushed to your repository!

Open the coverage/cov-repost/index.html using VSCode's live server plugin.

Notice how the coverage indicates we have not tested cases where the /authenticate route handler returns an error.