Skip to content
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 find module '@testing-library/jest-dom/matchers' #197

Closed
nharrisanalyst opened this issue Jan 30, 2020 · 6 comments · Fixed by #200, eapenzacharias/Calculator-REACT#16 or ericblade/quagga2-reader-qr#9
Labels
bug Something isn't working help wanted Extra attention is needed released

Comments

@nharrisanalyst
Copy link

I am getting the error

Cannot find module '@testing-library/jest-dom/matchers' from 'selector.test.js'

are the docs correct it seems to work when I do
import {
toBeInTheDocument
} from '@testing-library/jest-dom

image

image

@gnapse
Copy link
Member

gnapse commented Jan 31, 2020

Indeed. It seems we messed up when switching to v5. It's not enough to put a matchers.js file at the root. We also need to list it in the files entry of package.json, and not sure if that's enough.

@gnapse gnapse added bug Something isn't working help wanted Extra attention is needed labels Jan 31, 2020
@jgoz
Copy link
Collaborator

jgoz commented Jan 31, 2020

Adding it to files should be enough to make it work for JS users. There are no type definitions for jest-dom/matchers, so it will continue not working for TS users until someone adds them to DT.

@gnapse
Copy link
Member

gnapse commented Jan 31, 2020

I wonder if, in addition to add it to files, we also need to stop using import and go back to require. Asking because I see that the root extend-expect.js does that when importing (or rather requiring) the corresponding extend-expect.js from inside src/.

@jgoz
Copy link
Collaborator

jgoz commented Jan 31, 2020

I think they can be left as import statements inside of src, but the matchers.js file itself should probably use require. It should also import the files from dist instead of src. And it should re-export using module.exports.

@gnapse
Copy link
Member

gnapse commented Feb 3, 2020

I created #200 to tackle this. Tried those changes locally in a playground repo that uses jest-dom by selectively importing custom matchers and extending expect manually, and it works, whereas I confirmed it does not work with these changes in place, as @nharrisanalyst reported.

@gnapse
Copy link
Member

gnapse commented Feb 3, 2020

🎉 This issue has been resolved in version 5.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment