Jest: Watch a test file
11 April 2023 (Updated 11 April 2023)
On this page
Using jest
Syntax
jest --watch <test-file-pattern>
Example
jest --watch userService.spec.ts
This will watch userService.spec.ts
for changes and re-run the tests related to that file.
Using NPM script
Assuming you have a test:watch
NPM script that looks like this:
{
// other NPM scripts
"test:watch": "jest--watch"
}
You can run
npm run test:watch -- <test-file-name>
Sources
Tagged:
Jest