Closed ambarvm closed 2 months ago
@testing-library/react
import { act } from '@testing-library/react'; act(() => {});
Act is marked as deprecated.
The signature (callback: () => VoidOrUndefinedOnly): void of act is deprecated.
Updated react to 18.3 in an existing project
act imported from testing library is marked deprecated.
https://stackblitz.com/edit/rtl-template-749zgo?file=src%2FApp.test.tsx
The js code correctly exports the new React.act which is not deprecated. https://github.com/testing-library/react-testing-library/blob/f6a1677501b53471f6a989078726aeb0dea114be/src/act-compat.js#L5 But the types file always exports the type of deprecated act. https://github.com/testing-library/react-testing-library/blob/f6a1677501b53471f6a989078726aeb0dea114be/types/index.d.ts#L10
React.act
Add another condition to the type definition to export React.act when it is present.
export const act: typeof reactAct extends undefined ? (typeof reactDomTestUtilsAct extends undefined ? (callback: () => void) => void : typeof reactDomTestUtilsAct) : typeof reactAct
I think we can also remove the case for act not being present since react peerDependency is ^18.
export const act: typeof reactAct extends undefined ? typeof reactDomTestUtilsAct : typeof reactAct
Thanks @ambarvm, I've created https://github.com/testing-library/react-testing-library/pull/1319 to resolve this :)
@testing-library/react
version: 15.0.5Relevant code or config:
Act is marked as deprecated.
What you did:
Updated react to 18.3 in an existing project
What happened:
act imported from testing library is marked deprecated.
Reproduction:
https://stackblitz.com/edit/rtl-template-749zgo?file=src%2FApp.test.tsx
Problem description:
The js code correctly exports the new
React.act
which is not deprecated. https://github.com/testing-library/react-testing-library/blob/f6a1677501b53471f6a989078726aeb0dea114be/src/act-compat.js#L5 But the types file always exports the type of deprecated act. https://github.com/testing-library/react-testing-library/blob/f6a1677501b53471f6a989078726aeb0dea114be/types/index.d.ts#L10Suggested solution:
Add another condition to the type definition to export React.act when it is present.
I think we can also remove the case for act not being present since react peerDependency is ^18.