Running Tests Automatically and Code Coverage
Explore how to run Jest tests automatically using watch mode and learn to measure code coverage with Jest flags. Understand how to improve test completeness and maintain efficient test-driven development cycles in your React projects.
We'll cover the following...
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:
As soon as you hit save, your console output should change:
...