"ReferenceError: You are trying to `import` a file after the Jest environment has been torn down" when using jest with mongoose "ReferenceError: You are trying to `import` a file after the Jest environment has been torn down" when using jest with mongoose mongoose mongoose

"ReferenceError: You are trying to `import` a file after the Jest environment has been torn down" when using jest with mongoose


I resolved this by using the jest-mongodb preset which supplies all the async config necessary for Jest to run smoothly with MongoDB.

Note that Mongoose doc warns against using jest.useFakeTimers() because they "stub out global functions like setTimeout() and setInterval(), which causes problems when an underlying library uses these functions"