Roman
Roman

Reputation: 21757

Jest error: Mongoose: looks like you're trying to test a Mongoose app with Jest's default jsdom test environment

Testing with Jest endpoint of ExpressJS with Mongoose middleware I came across with the following error:

Mongoose: looks like you're trying to test a Mongoose app with Jest's default jsdom test environment. Please make sure you read Mongoose's docs on configuring Jest to test Node.js apps: http://mongoosejs.com/docs/jest.html

What is the issue?

Upvotes: 2

Views: 4204

Answers (2)

Arun Singh
Arun Singh

Reputation: 231

"scripts": {
    "test": "jest --testEnvironment=node --verbose --forceExit --watchAll --maxWorkers=1"
 }
  1. add --testEnvironment=node to package.json as shown above.
  2. Then re-run "npm test"

Issue Resolved!

Upvotes: 13

Roman
Roman

Reputation: 21757

According to official documentation for Mongoose you need to solve this problem by creating jest.config.js with the following content:

module.exports = {
  testEnvironment: 'node'
};

And guess what? It has solved my issue pretty painlessly :-)

Upvotes: 8

Related Questions