Upgrade to 6.0.0 no longer augments `expect`
Naddiseo opened this issue · comments
@testing-library/jest-dom
version: 6.0.0node
version: 18.17.1npm
(oryarn
) version: yarn 3.5.1dom-testing-library
version: (if applicable): 9.3.1react-testing-library
version: (if applicable): 14.0.0jest
: 29.6.2- typescript: 5.1.6
Relevant code or config:
- Project uses
"type": "module"
, typescript, nextjs - We (used to) import "@testing-library/jest-dom/expect-extend" in our
setupTests.js
, since upgrading to 6.0.0, I see that we're now supposed to import just "@testing-library/jest-dom" - However, now matchers don't seem to be there
What you did:
Upgrading @testing-library/jest-dom
to version 6.0.0
What happened:
- We (used to) import "@testing-library/jest-dom/expect-extend" in our
setupTests.js
, since upgrading to 6.0.0, I see that we're now supposed to import just "@testing-library/jest-dom" - However, now matchers don't seem to be there
Property 'toBeInTheDocument' does not exist on type 'Matchers<void, HTMLElement | null>'.
Reproduction:
https://codesandbox.io/s/react-testing-library-demo-forked-l27vm5
Problem description:
The extended matchers don't seem to be there any more.
Suggested solution:
I haven't verified, but I suspect it might be because I'm using "type":"module"
. The code sandbox link above manages to reproduce the issue I'm seeing
Can you try converting your setupTests.js
file to a TypeScript file (setupTests.ts
) and then including that in your tsconfig.json
?
@jgoz changing the setupTests to a .ts
file seems to have worked, thanks! I don't understand why though. Perhaps the need for a .ts
setup file can be documented?
Great! Glad it worked. It is documented in the With TypeScript section:
If you're using TypeScript, make sure your setup file is a
.ts
and not a.js
to include the necessary types.
@httpete And setup-tests.ts is listed in includes
or files
in your tsconfig.json?
I was able to fix this by including this in my test-utils.ts. I guess it was working by accident before, picking up the types in the context. I am set thanks!
import '@testing-library/jest-dom';