-
Notifications
You must be signed in to change notification settings - Fork 401
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
Cannot use @testing-library/jest-dom
directly in setupFilesAfterEnv
#517
Comments
It still works for running tests, but you will need to follow the "Using with TypeScript" documentation in the Readme: https://github.com/testing-library/jest-dom#with-typescript You can also use one of the following techniques to avoid creating a separate test setup file:
"compilerOptions": {
"types": ["@testing-library/jest-dom"]
} Or put it in a .d.ts file that's included like src/jest-dom-types.d.ts /// <reference types="@testing-library/jest-dom/types/jest.d.ts" /> |
I take your point that it would work if I interpreted the README as meaning that the Would it be reasonable to ask that the documentation be more explicit that the I completely understand that this is probably entirely my fault and that it worked before was by accident not design. Still, it seems like an easy mistake to prevent someone else also making. |
The @testing-library/jest-dom new version has a breaking change. The type must be included in the tscfong file as explain in this issue testing-library/jest-dom#517 (comment)
That's definitely reasonable. I think the TypeScript section was written assuming you had read the previous "Using with" sections which makes it more obvious that it's referring to a separate file, but it would be confusing when read in isolation. I think it's also worth documenting the techniques that avoid a separate setup file, which I put in my previous comment. |
The @testing-library/jest-dom new version has a breaking change. The type must be included in the tscfong file as explain in this issue testing-library/jest-dom#517 (comment)
The @testing-library/jest-dom new version has a breaking change. The type must be included in the tscfong file as explain in this issue testing-library/jest-dom#517 (comment)
The @testing-library/jest-dom new version has a breaking change. The type must be included in the tscfong file as explain in this issue testing-library/jest-dom#517 (comment)
The @testing-library/jest-dom new version has a breaking change. The type must be included in the tscfong file as explain in this issue testing-library/jest-dom#517 (comment)
Thanks, glad I’m not barking up the wrong tree! I will gladly craft such an amendment in a PR if that’s helpful/welcome. (I wouldn’t like to presume.) |
That would be super helpful! |
This approach unfortunately causes
This didn't work at all for me. What did work, however, was this: /// <reference types="@testing-library/jest-dom" /> 🎉 |
See testing-library/jest-dom#517 for more info
See testing-library/jest-dom#517 for more info
@testing-library/jest-dom
version: 6.0.1node
version: 18.13.0npm
(oryarn
) version: 9.8.1Relevant code or config:
What you did:
Upgrade from
5.17.0
to6.0.1
.Ran
jest
What happened:
An error was reported:
Reproduction:
I could not make this work in CodeSandbox, but here is a reproduction repo.
Problem description:
Previously directly referencing
'@testing-library/jest-dom'
in thesetupFilesAfterEnv
list worked just fine. After6.0.0
it is necessary to create a separate file that has theimport '@testing-library/jest-dom'
line in it.Suggested solution:
Sorry, I don't know enough about how these mechanisms work to suggest a fix.
The text was updated successfully, but these errors were encountered: