"expect is not defined" when using with jest
See original GitHub issue@testing-library/jest-domversion: 4.0.0nodeversion: 12.8.0npm(oryarn) version: 6.10.2
Relevant code or config:
Jest config
module.exports = {
snapshotSerializers: ['jest-emotion'],
setupFilesAfterEnv: ['./config/jest.js']
};
jest.js file
require('@testing-library/jest-dom/extend-expect');
What you did:
run the npm test
What happened:
Getting error expect is not defined …
Determining test suites to run...
● Test suite failed to run
ReferenceError: expect is not defined
at Object.<anonymous> (node_modules/@testing-library/jest-dom/dist/extend-expect.js:7:1)
at Object.newLoader [as .js] (node_modules/pirates/lib/index.js:104:7)
at Object.<anonymous> (node_modules/@testing-library/jest-dom/extend-expect.js:2:1)
Reproduction:
https://github.com/tomitrescak/react-boilerplate/tree/Demo
Problem description:
I cannot run my tests
Suggested solution:
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
Top Results From Across the Web
React + Jest Testing Error - ReferenceError: expect is not ...
js ○ Test suite failed to run ReferenceError: expect is not defined 3 | import Adapter from "enzyme-adapter-react-16"; 4 | import '@testing- ...
Read more >How to fix an error about “expect is not defined” | by Kyosuke Ito
When I tried to connect my app to firebase database for testing, I got an error about “expect is not defined”. I found...
Read more >Expect - Jest
The expect function is used every time you want to test a value. You will rarely call expect by itself. Instead, you will...
Read more >Expect · Jest
Use .toBeDefined to check that a variable is not undefined. For example, if you just want to check that a function fetchNewFlavorIdea() returns...
Read more >From Jest to Vitest - Migration and Benchmark
Here's my path for migrating a project using Jest into using Vitest along with some benchmarking. ... describe is not defined. Well, Jest...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just to collate the above together without having to click about through links and do reading, my solution was:
In
jest.config.js, replace:With:
Found the culprit. Sorry for bothering. The same setup file was run in the global setup.