Description
@testing-library/jest-dom
version: 6.6.2node
version: 20.10.0- vitest version: 2.1.3
npm
(oryarn
) version: 10.2.3
Relevant code or config / Reproduction:
minimun reproduce demo: https://stackblitz.com/edit/vitejs-vite-ydhnrx?file=src%2FApp.test.tsx
What you did:
Bootstramp a starter repo with vitest & testing-library (vitest should be in global mode, and there is no import xxx from 'vitest'
in the whole project)
Problem description / What happened:
The toHaveTextContent
should be a matcher of expect, and also is working in runtime, but a type error is thrown.
You can run npm run build
to see the error
Suggested solution:
According to the documents of vitest, to extend a matcher, we have to import the "vitest"
module otherwise the interface merge might not work as expected
So we could add this line of code to top of the definition
import "vitest"
You can try adding this in the stackbliz repo's dependency (jumping to the source code by ctrl + click the import) and run npm run build
again, the type error should be fixed