Jest错误:猫鼬:似乎您正在尝试使用Jest的默认jsdom测试环境测试Mongoose应用程序

时间:2019-12-07 05:58:47

标签: express mongoose jestjs

使用Mongoose中间件对ExpressJS的Jest端点进行测试时遇到以下错误:

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

出了什么问题?

2 个答案:

答案 0 :(得分:8)

"scripts": {
    "test": "jest --testEnvironment=node --verbose --forceExit --watchAll --maxWorkers=1"
 }
  1. 将--testEnvironment = node添加到package.json中,如上所示。
  2. 然后重新运行“ npm测试”

问题已解决!

答案 1 :(得分:1)

根据猫鼬的官方documentation,您需要通过创建具有以下内容的jest.config.js来解决此问题:

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

你猜怎么着?它非常轻松地解决了我的问题:-)