import '@testing-library/jest-dom/extend-expect';
expect(screen.getByText('User does not exist.')).toBeInTheDocument()
I’m writing the unit test for my web app, I use toBeInTheDocument() in my code, but after i run npm test in terminal, it shows that ‘Cannot find module ‘@testing-library/jest-dom/extend-expect’ from ‘jest.setup.js”.
I have a jest.setup.js file which includes the code:require(‘@testing-library/jest-dom/extend-expect’);
and also a jest.config.js file which includes the code:
setupFilesAfterEnv:["./jest.setup.js"],
and I also import ‘@testing-library/jest-dom/extend-expect’; in my test.tsx file, also check the node_modules there is @testing-library/jest-dom under it.
what should I do now?`
2
Answers
I also encountered the same problem, and the issue was with the @testing-library/jest-dom version 6.1.4, which I changed to version 5.16.5
Remove extend-expect from your import: