jest-dom
jest-dom copied to clipboard
fix: proper vitest ts support (#515)
What:
This PR extends Vitest's default Assertion interface to fix the toBeInTheDocument ts error when using Vitest (#515).
Why:
I don't know (still cannot reproduce #515 on my own computer). But from this comment, adding
/// <reference types="@testing-library/jest-dom" />
in custom vitest-setup.ts file would fix this error in that situation. Therefore I think the types/vitest.d.ts may need to be updated.
And when I install this repo's dependencies by pnpm and running tsc -p types/__tests__/vitest, there would be similar errors of #515 (if using npm or import '../../jest' instead of import '../../vitest' like that comment, there would be no error). This PR would fix this error even using pnpm.
How:
https://vitest.dev/guide/extending-matchers.html
Checklist:
- [x] Documentation
- [x] Tests
- [x] Updated Type Definitions
- [x] Ready to be merged
Confirmed in my office computer (a pnpm monorepo with the With Vitest and With TypeScript setup):
- Switch to the fork version by changing
package.jsonto"@testing-library/jest-dom": "https://github.com/nyaapass/jest-dom", the error can be fixed: -
- When back to the original
@testing-library/[email protected]version, the #515 error would be shown again: -
What is the reason that this change is not being merged in? Vitest removed @vitest/expect interface, so when @testing-library/jest-dom/vitest is trying to extend @vitest/expect interface, it just does nothing. By the way I see it, this change actually corrects the way you are expected to extend the interface since 0.x.x version, so what is the hold up here?
What is the reason that this change is not being merged in? Vitest removed
@vitest/expectinterface, so when@testing-library/jest-dom/vitestis trying to extend@vitest/expectinterface, it just does nothing. By the way I see it, this change actually corrects the way you are expected to extend the interface since 0.x.x version, so what is the hold up here?
Alright, other PR was changed with these changes https://github.com/testing-library/jest-dom/commit/06d19ba759a5ff4b51417cc9a7ecb72c785eb74d waiting for release I guess
I guess we can close this as superseded by #612