Reputation: 7460
Since today, I started to get this type error and bunch of others regarding "@testing-library/react"
I followed a similar GitHub issue and they are seem to be relevant but not an answer of why this might happen!
Things that I'm getting this error on are:
I Also tried using this page it helped a bit but still i really have no idea where to get waitFor, waitForElementToBeRemoved and others that might needed. they are coming from @testing-library/react
but why typescript gives me that error I absolutely have no idea!
I'm using pnpm and my pkg versions are latest ones:
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
Why is this happening?
Upvotes: 5
Views: 11876
Reputation: 51
To solve the above error you need to install @testing-library/dom
:
yarn add -D @testing-library/dom
Upvotes: 4
Reputation: 1
I was looking into a very old React project of mine that had been barely been updated last year and come across this problem. This is what worked for me:
npm install --save-dev @testing-library/jest-dom @testing-library/react @testing-library/dom --legacy-peer-deps
Then go into src/setupTests.ts
and delete the line import '@testing-library/jest-dom/extend-expect';
as well, as I'm guessing you're going to run into that issue as well, but maybe not.
Good luck!
Upvotes: 0
Reputation: 1654
For me this was happening inside a monorepo because I had one of my packages with "@testing-library/dom" as a dependency. My structure was something like this:
Because only package c
had @testing-library/dom
, yarn was installing it into packages/c/node_modules
which made it inaccessible for packages a
and b
.
The solution was to add @testing-library/dom
to the list of dependencies
in the package.json
for packages a
and b
too. Or alternatively tweak the workspaces.nohoist
value in the package.json
at the root of the monorepo.
Upvotes: 0
Reputation: 7460
So after investigating this issue a lot, I figured out a solution from some other projects of mine which was exactly using the same pkgs but they did not have any error.
So I clicked on the type definition of waitFor
in there and started to chase that within node_modules directory of that project.
after a while, i did notice that waitFor
comes from @testing-library/dom
and i wondered if i have that package installed or not!
soon after I installed that package, it fixed my issue BUT I wonder what this pkg @testing-library/jest-dom
doing then?
Upvotes: 9