gpt4 book ai didi

node.js - 创建 jest.config.file 的指南

转载 作者:搜寻专家 更新时间:2023-10-31 23:44:32 24 4
gpt4 key购买 nike

我在我的 Node 应用程序中使用 Jest,我在控制台中收到以下消息:

Mongoose:看起来您正在尝试使用 Jest 的默认 jsdom 测试环境测试 Mongoose 应用程序。请确保您阅读了有关配置 Jest 以测试 Node.js 应用程序的 Mongoose 文档:http://mongoosejs.com/docs/jest.html

我已经阅读了文档,但感觉他们希望我在第一次使用这个库时熟悉它。文档说要添加这段代码:

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

到我的 jest.config.js 文件,但是这个文件在哪里?我应该在我的目录中的什么地方创建这个文件?我在项目文件夹的根目录中创建了该文件并添加了之前的代码,但该消息仍保留在控制台中。我该如何解决这个问题?

最佳答案

您可以直接在您的package.json 文件中配置jest。

  ...,  "scripts": {    "start": "nodemon --exec babel-node server/index.js",    "build": "babel server --out-dir dist",    "serve": "node dist/index.js",    "test": "jest --watchAll --verbose --detectOpenHandles ./server/api"  },  "jest": {    "testEnvironment": "node"  },  ...

关于node.js - 创建 jest.config.file 的指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53642430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com