testing-library / jest-dom

:owl: Custom jest matchers to test the state of the DOM
https://testing-library.com/docs/ecosystem-jest-dom
MIT License
4.45k stars 401 forks source link

fix: remove recursive type reference in vitest types #636

Closed G-Rath closed 1 month ago

G-Rath commented 1 month ago

What:

Replaces the dynamic lookup of the return type of expect.stringContaining with the underlying type

Why:

This resolves the TypeScript errors introduced by #612, as described in #629

How:

By replacing the use of expect.stringContaining with a concrete type - I don't actually know why ReturnType was being used in the first place given that expect.stringContaining has a return type of any and I don't really see that changing anytime in the future.

Checklist:

Resolves #632 Resolves #629

G-Rath commented 1 month ago

@gnapse would it be possible to have this reviewed? as currently all typescript types are broken meaning we've having to patch this manually for our CIs to pass 😅

gnapse commented 1 month ago

@all-contributors please add @G-Rath for code

allcontributors[bot] commented 1 month ago

@gnapse

I've put up a pull request to add @G-Rath! :tada:

github-actions[bot] commented 1 month ago

:tada: This PR is included in version 6.6.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

BR0kEN- commented 1 month ago

This change results in the following:

Error: src/components/SiteNav/SiteNav.test.tsx(59,22): error TS2339: Property 'toHaveAttribute' does not exist on type 'Assertion<HTMLElement>'.
Error: src/components/SiteNav/SiteNav.test.tsx(60,22): error TS2339: Property 'toHaveTextContent' does not exist on type 'Assertion<HTMLElement>'.
Error: src/components/SiteNav/SiteNav.test.tsx(84,22): error TS2339: Property 'toHaveClass' does not exist on type 'Assertion<HTMLElement>'.
Error: src/components/SiteNav/SiteNav.test.tsx(88,18): error TS2339: Property 'toHaveClass' does not exist on type 'Assertion<HTMLElement>'.
Error: src/tests/App.test.tsx(19,66): error TS2339: Property 'toBeInTheDocument' does not exist on type 'Assertion<HTMLElement>'.
Error: src/tests/components/CollapsibleContent.test.tsx(46,60): error TS2339: Property 'toBeInTheDocument' does not exist on type 'Assertion<HTMLElement>'.
Error: src/tests/components/CollapsibleContent.test.tsx(48,37): error TS2339: Property 'toBeVisible' does not exist on type 'Assertion<HTMLDivElement>'.
Error: src/tests/components/CollapsibleContent.test.tsx(68,30): error TS2339: Property 'toHaveClass' does not exist on type 'Assertion<HTMLDivElement>'.
Error: src/tests/components/CollapsibleContent.test.tsx(71,62): error TS2339: Property 'toBeInTheDocument' does not exist on type 'Assertion<HTMLElement>'.
Error: src/tests/components/CollapsibleContent.test.tsx(75,33): error TS2339: Property 'toBeVisible' does not exist on type 'Assertion<HTMLElement | null>'.
Error: src/tests/components/CollapsibleContent.test.tsx(90,18): error TS2339: Property 'toHaveClass' does not exist on type 'Assertion<Element | null>'.
Error: src/tests/components/CollapsibleContent.test.tsx(111,33): error TS2339: Property 'toHaveClass' does not exist on type 'Assertion<HTMLElement | null>'.
Error: src/tests/components/DownloadLink.test.tsx(21,18): error TS2339: Property 'toBeInTheDocument' does not exist on type 'Assertion<HTMLElement>'.
Error: src/tests/components/DownloadLink.test.tsx(22,18): error TS2339: Property 'toHaveAttribute' does not exist on type 'Assertion<HTMLElement>'.
Error: src/tests/components/DownloadLink.test.tsx(23,18): error TS2339: Property 'toHaveAttribute' does not exist on type 'Assertion<HTMLElement>'.
gnapse commented 1 month ago

@G-Rath can you look into it? I have no access to an environment with jest-dom and vitest right now.

greysteil commented 1 month ago

FWIW I'm not seeing the errors @BR0kEN- is - the change is working well for me (and I had the issue @G-Rath had with jest-dom and vitest before).

BR0kEN- commented 1 month ago

Thanks for the fast reply and apologies, I had to not post that before a little of research.

I had no @testing-library/jest-dom added to the compilerOptions.types of the tsconfig.json and it worked. After this change, which is logical, it stopped. Fortunately, the fix is easy.