Watch and rerun Jest JS tests

Martin Dow picture Martin Dow · Aug 24, 2014 · Viewed 38k times · Source

The Jest documentation suggests using npm test to execute tests.

Is there a way of watching your source and tests to rerun Jest tests automatically when relevant files have been changed?

Answer

wuct picture wuct · May 3, 2015

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