Running Tests Automatically and Code Coverage

In this lesson, we will be writing tests while getting introduced to different features of Jest.

Running Jest tests automatically

Jumping to the console every time you want to run some tests is a chore. Happily, Jest has a “watch mode” where it automatically re-runs all tests when it detects any change to a test file or a source file dependent on a test.

To start Jest in watch mode, run it with the --watchAll flag:

$ npx jest --watchAll

Now you should see the same failure result as before. Try saving either index.js or index.test.js, and the test will re-run. You can press q at any time to quit. For now, leave Jest watch mode running.

Getting to green

Since Jest is watching your project, see if you can tackle the "FizzBuzz" test case:

Get hands-on with 1400+ tech skills courses.