Property 'toBeInTheDocument' does not exist on type 'Matchers<any>'
Most of the solutions above seems to tackle Babel or ESLint. If you have this problem with tslint
and pure Typescript it's enough to add:@testing-library/jest-dom
to your types
So that in your tsconfig.json:
"types": ["node", "jest", "@testing-library/jest-dom"],
Please also bare in mind that you should include that library into Jest. Rather than import it in every file it is better to do it inside the config file:
setupFilesAfterEnv: [ "<rootDir>/support/setupTests.js"],
and then in the file setupTests.js
:
import '@testing-library/jest-dom/extend-expect'
or even swap to require()
if using directly TypeScript.