react-testing-library: [4.1.3] Cannot find module 'jest-dom/extend-expect'
react-testing-libraryversion: 4.1.4reactversion: 16.4.1nodeversion: 9.11.1npm(oryarn) version: yarn 1.3.2
Relevant code or config:
// occurring error this line
import 'jest-dom/extend-expect'
entire test code https://github.com/ryota-murakami/redux-boilerplate-less-architecture/blob/master/src/pages/github/index.test.js
What you did:
What happened:
Test Broke with Cannot find module 'jest-dom/extend-expect'
Reproduction:
-
In 4.1.3 case, the above Error occurred. https://circleci.com/gh/ryota-murakami/redux-boilerplate-less-architecture/569?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link
-
In 4.1.2 case, test is all green. (https://circleci.com/gh/ryota-murakami/redux-boilerplate-less-architecture/591?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link)
I don’t know why is that happening because there is no jest-dom change [https://github.com/kentcdodds/react-testing-library/compare/v4.1.2...v4.1.3](between v4.1.2
v4.1.3).
something of dom-testing-liblary? thanks😀
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (3 by maintainers)
Commits related to this issue
- fix(files): fix defineProperty for files Closes #138 — committed to julienw/react-testing-library by deleted user 6 years ago
- Missing syntax update for tests Had to forget (at least) one https://github.com/testing-library/react-testing-library/issues/138#issuecomment-1716326742 — committed to ceithir/sakkaku by ceithir 8 months ago
If some of you still have the problem: I fixed it by using
instead of
jest-dom/jest-dom/extend-expectThis is the recommanded usage by the official documentation
replace import “jest-dom/jest-dom/extend-expect”; with import “@testing-library/jest-dom/extend-expect”;
It’s a separate package
Thanks it works for me.
You have to install jest-dom manually. Good luck!
Step 1: Uninstall jest-dom(deprecated one) npm uninstall jest-dom
Step 2:Install testing-library/jest-dom npm i @testing-library/jest-dom
Step 3:Replace import “jest-dom/jest-dom/extend-expect”; with import “@testing-library/jest-dom/extend-expect”;
Thanks @stevenYouhana
any update on this? There’s still a lot of mixed info out there - jest-dom is now packaged in, toBeInTheDocument must come from jest-dom, jest-dom is deprecated, it’s @testing-library/jest-dom now, you need to import it, you don’t need to import it… All the set-up guides are out of date.
If I
import {toBeInTheDocument} from '@testing-library/jest-dom'then I’m toldCannot find module '@testing-library/jest-dom'and if I don’t thenTypeError: expect(...).toBeInTheDocument is not a functionFYI Currently the official documentation recommend us to use
// In tsconfig.json
"include": [ "./jest-setup.ts"],I’ve done that; its in my package.json (^3.1.3)
I am still getting this error nothing is fixing it OK I just got this error
jest-dom has moved to @testing-library/jest-dom. Please uninstall jest-dom and install @testing-library/jest-dom instead, or use an older version of jest-dom. Learn more about this change here: https://github.com/testing-library/dom-testing-library/issues/260 Thanks!
@s-Hale Did you install
@testing-library/jest-dom? Either via https://github.com/testing-library/jest-dom#installation oryarn add -D @testing-library/jest-domI am having the same problem - what does “You have to install jest-dom manually.” mean? Thanks.