79541358

Date: 2025-03-28 11:59:42
Score: 1
Natty:
Report link

In my case (TypeScript based project), I had to do the following to fix the error:

  1. Add types for jest-dom package (@testing-library/jest-dom has already been added)

    yarn add -D @types/testing-library__jest-dom

  2. Add below under compilerOptions in tsconfig.json

    "types": ["node", "jest", "@testing-library/jest-dom"],

  3. Add below on top of your test files (please refer @Greg Wozniak's comment above to include below import statement only in setupTests.js rather than import it in every test file)

    import '@testing-library/jest-dom'

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Greg
  • Low reputation (1):
Posted by: Sasiru Tharinda