After Jest executes our tests, it provides us with the following options:
> Press f to run only failed tests.
> Press o to only run tests related to changed files.
> Press p to filter by a filename regex pattern.
> Press t to filter by a test name regex pattern.
> Press q to quit watch mode.
> Press Enter to trigger a test run.
These options let us specify what tests should be executed, which is really useful as the number of tests grows. Let's explore some of these options:
- If we press F, Jest will execute only the tests that have failed. In our code, we get confirmation that we have no failing tests:
- Let's press F to exit this option and take us back to all the options that are available.
- Now, let's press P. This allows us to test a specific file or a collection of files with names matching a regular expression pattern. Let's enter form when prompted for the filename pattern:
Our test in Form.test.tsx will then be executed.
- We are going to leave the filename filter on and press T. This will allow us to add an additional filter by test name. Let's enter required:
Our test on the required function will then be executed.
- To clear the filters, we can press C.
If we receive an error—watch is not supported without git/hg, please use --watchAll, this will be because our project isn't in a Git repository. We can resolve the issue by entering the git init command in the Terminal.
We have a good handle on the options available to execute our tests now.