Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guidance creating jest.config.file

Tags:

node.js

jestjs

I'm using Jest in my Node app and I get the following message in the console:

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

I have read the documentation but it feels like they expect me to be familiar with this library when this is my first time using it. The documentation says to add this piece of code:

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

To my jest.config.js file, but where is this file?, where in my dir am I supposed to create this file? I created the file in the root of my project folder and added the previous piece of code but the message still remains in the console. How can I solve this?

like image 412
Gilbert R. Avatar asked Jan 27 '23 01:01

Gilbert R.


1 Answers

You can configure jest directly on your package.json file.

  ...,
  "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"
  },
  ...
like image 68
Marco Martins Avatar answered Jan 31 '23 21:01

Marco Martins