Closed
Description
@testing-library/react
version: 15.0.5- Testing Framework and version: jest@29.2.1
- DOM Environment: jsdom@20.0.1
Relevant code or config:
import { act } from '@testing-library/react';
act(() => {});
Act is marked as deprecated.
The signature (callback: () => VoidOrUndefinedOnly): void of act is 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.
But the types file always exports the type of deprecated act.
react-testing-library/types/index.d.ts
Line 10 in f6a1677
Suggested solution:
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
Metadata
Metadata
Assignees
Labels
No labels