{"id":615,"hash":"b664d47b897c3883a9df2cef60c509ba4986c81317227ab6779a9aa23ba9dda4","pattern":"eslint throws `no-undef` errors when linting Jest test files","full_message":"I'm using Jest to write some specs and ESLint to lint the styling. \n\nFor my foo.spec.js tests, eslint keeps throwing the following errors. It seems to think that jest, beforeEach, afterEach, etc... are not defined in that file. \n\n   11:1   error  'beforeEach' is not defined  no-undef\n   12:3   error  'jest' is not defined        no-undef\n   14:13  error  'jest' is not defined        no-undef\n   18:1   error  'afterEach' is not defined   no-undef\n   20:1   error  'describe' is not defined    no-undef\n   21:3   error  'it' is not defined          no-undef\n   25:5   error  'expect' is not defined      no-undef\n   28:5   error  'expect' is not defined      no-undef\n   31:5   error  'expect' is not defined      no-undef\n   34:3   error  'it' is not defined          no-undef\n   38:5   error  'expect' is not defined      no-undef\n   41:5   error  'jest' is not defined        no-undef\n   42:5   error  'expect' is not defined      no-undef\n   43:5   error  'expect' is not defined      no-undef\n   46:3   error  'it' is not defined          no-undef\n   54:5   error  'expect' is not defined      no-undef\n   58:5   error  'jest' is not defined        no-undef\n\nI believe those are included by jest automatically and so they don't need to be explicitly imported in my spec files. In fact the only thing I import via my jest.setup.js file is\n\nimport \"react-testing-library/cleanup-after-each\";\nimport \"jest-dom/extend-expect\";\n\nIs there a way to eliminate these errors without having to disable eslint rules at the top of each individual file or inline? \n\nThanks!","ecosystem":"npm","package_name":"unit-testing","package_version":null,"solution":"Please, add the following to your .eslintrc file:\n\n{\n  \"overrides\": [\n    {\n      \"files\": [\n        \"**/*.spec.js\",\n        \"**/*.spec.jsx\"\n      ],\n      \"env\": {\n        \"jest\": true\n      }\n    }\n  ]\n}","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/56398742/eslint-throws-no-undef-errors-when-linting-jest-test-files","votes":123,"created_at":"2026-04-19T04:51:24.122691+00:00","updated_at":"2026-04-19T04:51:27.267787+00:00"}