-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"expect is not defined" when using with jest #122
Comments
Found the culprit. Sorry for bothering. The same setup file was run in the global setup. |
If anyone else who hits a roadblock here like me, have a look at this comment to solve the issue: enzymejs/enzyme-matchers#86 (comment) |
Ran into this issue on CI server runnning node v10.10 after upgrading the following dependencies:
and having switched from running tests with Can confirm that upgrading node to v10.15 fixed the problem, assuming the jest setup file config is correctly defined. |
Just to collate the above together without having to click about through links and do reading, my solution was: In
With:
|
had the same issue, only in CI, but the setup file was under |
Thanks, @MaffooBristol! Your solution works! |
If anyone is using Vue Test Utils and still having this problem after trying these solutions, make sure all of your packages are up to date in package.json then delete your node modules folder and run npm install again.
|
Just to add my findings: you can do the exact same thing as a command line option when running an npm script. I needed this because I was using react-scripts, and wanted to change the default name ( In my package.json scripts entries I had |
Sorry this was not working for me I was forced to import the expect function from Chai |
https://stackoverflow.com/a/69222856/9518005 |
- Note: using `npm install --save-dev` will also sort dependencies automatically. add: - @testing-library/jest-dom - Need to import in test/helpers.js: https://github.com/testing-library/jest-dom#installation - Need to use `setupFilesAfterEnv` instead: testing-library/jest-dom#122 update: - axe-core - jest, @types/jest - When upgrading to v27, we need to explicitly specify jsdom env: https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults - @testing-library/react - @testing-library/react-hooks - @testing-library/user-event squash
- Note: using `npm install --save-dev` will also sort dependencies automatically. add: - @testing-library/jest-dom - Need to import in test/helpers.js: https://github.com/testing-library/jest-dom#installation - Need to use `setupFilesAfterEnv` instead: testing-library/jest-dom#122 update: - axe-core - jest, @types/jest - When upgrading to v27, we need to explicitly specify jsdom env: https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults - @testing-library/react - @testing-library/react-hooks - @testing-library/user-event - nyc - Needed to be updated to handle issue when testing w/ node 14: https://github.com/appfolio/react-gears/runs/4693696609?check_suite_focus=true
Note that, if you don't have other setup to do after env, you can just include this in your Jest config:
...i.e., no need to create a separate Note: if you're using TypeScript, it will complain that the matchers don't exist. (TypeScript doesn't know about your Jest config, obviously.) To fix this, I created a
Since it's a |
@testing-library/jest-dom
version: 4.0.0node
version: 12.8.0npm
(oryarn
) version: 6.10.2Relevant code or config:
Jest config
jest.js file
What you did:
run the
npm test
What happened:
Getting error expect is not defined ...
Reproduction:
https://github.com/tomitrescak/react-boilerplate/tree/Demo
Problem description:
I cannot run my tests
Suggested solution:
The text was updated successfully, but these errors were encountered: