1.2 Run single file/folder
A well-tested project can have hundreds or thousands of tests/test files.
No matter how fast tests run, it can be useful to run only the tests in some files if we’re working to fix said tests.
Run a single Jest test file
With the CLI, you can run:
jest path/to/file
It will only run the tests in files that match path/to/file
.
If you don’t have the Jest CLI installed globally, you might need to use npx
or yarn
:
yarn jest path/to/file
# or
npx jest path/to/file
Run a single folder of Jest tests
With the CLI, you can run:
jest path/to/folder
It will only run the tests in files that match path/to/folder
.
If you don’t have the Jest CLI installed globally, you might need to use npx
or yarn
:
yarn jest path/to/folder
# or
npx jest path/to/folder
We’ve now seen how to run a single file or folder of files which is helpful when debugging or running only a subset of checks.
In the case where we need maximum granularity (usually while debugging), and we want to run or skip single tests or describe
blocks, we’ll need modifiers as per the next section.