Jest: ReferenceError: You are trying to `import` a file after the Jest environment has been torn down

Viewed 868

I'm using Jest to unit test my Sails JS application.

When the tests pass and finish, I'm getting this error:

Ran all test suites.

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From test/controllers/foo/bar.test.js.

      at readdir (node_modules/readdirp/readdirp.js:49:25)
      at FSWatcher.<anonymous> (node_modules/chokidar/lib/nodefs-handler.js:355:5)
      at FSWatcher.Object.<anonymous>.NodeFsHandler._handleDir (node_modules/chokidar/lib/nodefs-handler.js:406:18)
      at FSWatcher.<anonymous> (node_modules/chokidar/lib/nodefs-handler.js:455:19)
      at FSWatcher.<anonymous> (node_modules/chokidar/lib/nodefs-handler.js:460:16)
/.../node_modules/readdirp/readdirp.js:49
    var api          =  require('./stream-api')();
                                               ^

TypeError: require(...) is not a function
    at readdir (/.../node_modules/readdirp/readdirp.js:49:48)
    at FSWatcher.<anonymous> (/.../node_modules/chokidar/lib/nodefs-handler.js:355:5)
    at FSWatcher.Object.<anonymous>.NodeFsHandler._handleDir (/.../node_modules/chokidar/lib/nodefs-handler.js:406:18)
    at FSWatcher.<anonymous> (/.../node_modules/chokidar/lib/nodefs-handler.js:455:19)
    at FSWatcher.<anonymous> (/.../node_modules/chokidar/lib/nodefs-handler.js:460:16)

I set Jest timeout to 10000.

I also tried using Jest fake timers.

I've done the research before posting this question, but haven't found a good solution.

1 Answers
Related