Closed MatanBobi closed 2 months ago
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit 5ee9d3d2be9f5c7126540c262e6d9ed1f60e1e2a:
Sandbox | Source |
---|---|
react-testing-library-examples | Configuration |
How did you test this?
I've used npm link
locally to see that the error is there before I link and removed after I link. Having said that, I wasn't able to install an older type of react
and react-dom
(to see that the type is exported properly when act
isn't exported from react
), for some reason I always get the same d.ts files which show act from test-utils as deprecated and act from react exported so that's odd.
From your comment, I realized that we probably also need to define @types/react
as a peer dependency now? I saw that it's a dependency for @types/react-dom
so I'm not sure if we want to rely on that or not.
Edit: I think I understand what happened, since @types/react-dom
is our dependency and not a peer yet, this scenario is impossible because the types are bundled in our code. I'm always getting the types we install as part of RTL (as long as it's not a peer).
Yeah I don't think this ever worked for versions where react-dom/test-utils
didn't have act
.
TypeScript should error if you try to import something that doesn't exist.
We probably need to @ts-ignore
the React.act
import and then check if it's any
(typeof act extends never ? true : false
) instead of undefined
.
Let's double check this works in versions without React.act
by forcing an older version of @types/react
via overrides
(npm) or resolutions
(yarn, pnpm). Make sure to clear lockfile and node_modules if you use npm.
And we also need @types/react
as an optional peer dependency. We always needed that though since we already use React.ReactNode
. It just happened to work because TypeScript always makes namespaces available globally.
Using overrides
didn't help as I'm using link
so the dependency is still taken locally. I've tried installing an older version of @types/react
and @types/react-dom
and link. Things seem to work.
I've pushed the fixes. I'll also create a PR to the docs site to state that users will probably want to install @types/react
as it's a peer dependency now.
Following your idea @eps1lon, I've created this repo for repro: https://github.com/MatanBobi/rtl-deprecated-act-repro Main branch is old React (18.2.0) that shows no regression with type change, other two branches are:
@eps1lon Related docs PR: https://github.com/testing-library/testing-library-docs/pull/1390
Yesss thank you. This helped me. When I saw your post, I downloaded the latest version and my program started running, no warning after that. Tyty
npm install @testing-library/react@latest @testing-library/jest-dom@latest
Resolves https://github.com/testing-library/react-testing-library/issues/1316
What: This PR exports the correct act if available to avoid deprecation warnings.