jest-dom icon indicating copy to clipboard operation
jest-dom copied to clipboard

fix: proper vitest ts support (#515)

Open nyaapass opened this issue 1 year ago • 1 comments

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.

image

How:

https://vitest.dev/guide/extending-matchers.html

Checklist:

  • [x] Documentation
  • [x] Tests
  • [x] Updated Type Definitions
  • [x] Ready to be merged

nyaapass avatar Mar 11 '24 15:03 nyaapass

Confirmed in my office computer (a pnpm monorepo with the With Vitest and With TypeScript setup):

  • Switch to the fork version by changing package.json to "@testing-library/jest-dom": "https://github.com/nyaapass/jest-dom", the error can be fixed:
    • image
  • When back to the original @testing-library/[email protected] version, the #515 error would be shown again:
    • image

ecoms-ye avatar Mar 12 '24 01:03 ecoms-ye

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?

Dalcvi avatar Aug 21 '24 07:08 Dalcvi

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?

Alright, other PR was changed with these changes https://github.com/testing-library/jest-dom/commit/06d19ba759a5ff4b51417cc9a7ecb72c785eb74d waiting for release I guess

Dalcvi avatar Aug 21 '24 07:08 Dalcvi

I guess we can close this as superseded by #612

gnapse avatar Aug 29 '24 00:08 gnapse