Watch and rerun Jest JS tests

Solution 1:

Thanks to Erin Stanfill for pointing out, Jest already has support for automatically re-running. The better configuration for package.json would be

{
  "scripts": {
    "test": "jest"
  }
}

To turn on the watch mode, just use

$ npm run test -- --watch

Or

$ yarn run test --watch

Solution 2:

If you have npm test configured, you can just run npm test -- --watch.

Solution 3:

Start you tests in watch mode.

jest --watch fileName.test.js

As per documentation

Run tests that match this spec name (match against the name in describe or test, basically).

jest -t name-of-spec
// or in watch mode
jest --watch -t="TestName"