I installed jest v24.7.1
in my project with:
npm install jest -D
Then I start writing some test files, However I got these eslint errors:
'describe' is not defined. eslint (no-undef)
'it' is not defined. eslint (no-undef)
'expect' is not defined. eslint (no-undef)
eslintrc.js:
module.exports = {
env: {
browser: true,
es6: true
},
extends: ["airbnb", "prettier", "prettier/react"],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly"
},
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 2018,
sourceType: "module"
},
plugins: ["react"],
rules: {}
};
Should I add another rule or a plugin to fix this?
The jest object is automatically in scope within every test file. The methods in the jest object help create mocks and let you control Jest's overall behavior. It can also be imported explicitly by via import {jest} from '@jest/globals' .
To read TypeScript configuration files Jest requires ts-node . Make sure it is installed in your project.
Add following line in .eslintrc.js
file
"env": {
"jest": true
}
or
{
"plugins": ["jest"]
},
"env": {
"jest/globals": true
}
For more details check here, it also define the same.
Hope you installed eslint-plugin-jest
package.If not kindly go through for
Documentation.
All the configuration details of Configuring ESLint.
Add following comment line in head of your file
/* globals describe, expect, it */
For jest 27 all of this should not be necessary.
Kill node_modules
& package-lock.json
.
Then run npm i
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With