Search code examples
javascriptreactjstddjestjs

jest - error with watch mode


I am using Jest 21.2.1 to run my tests for a react application. Strangely when I run jest --watch (as mentioned here) to watch test cases for any change, I get an error as below

Determining test suites to run...Error: This promise must be present when running with -o.

I tried to check the Jest-CLI and found that the function is expecting two parameters and one of them is promise which is not passed in this case (Not sure how can I pass that). Maybe some missing config?

Any suggestion will be helpful to fix this.

getTestPaths(
  globalConfig,
  changedFilesPromise)
  {var _this2 = this;return _asyncToGenerator(function* () {
     const paths = globalConfig.nonFlagArgs;
     if (globalConfig.onlyChanged) {
        if (!changedFilesPromise) {
           throw new Error('This promise must be present when running with -o.');
        }

        return _this2.findTestRelatedToChangedFiles(changedFilesPromise);
     }

Note: It might be related to issue reported here.


Solution

  • Make sure you're running it in a Git repo (initialised with git init). Otherwise it doesn't know how to get only the changed files.

    If you don't want to run tests only on changed files, you can use --watchAll, which runs all the tests.