使用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
出了什么问题?
答案 0 :(得分:8)
"scripts": {
"test": "jest --testEnvironment=node --verbose --forceExit --watchAll --maxWorkers=1"
}
问题已解决!
答案 1 :(得分:1)
根据猫鼬的官方documentation,您需要通过创建具有以下内容的jest.config.js
来解决此问题:
module.exports = {
testEnvironment: 'node'
};
你猜怎么着?它非常轻松地解决了我的问题:-)