Jest: Watch a test file
11 April 2023 (Updated 8 April 2024)
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
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment