Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

act shows up as deprecated when using react 18.3 #1316

Closed
ambarvm opened this issue Apr 28, 2024 · 1 comment · Fixed by #1319
Closed

act shows up as deprecated when using react 18.3 #1316

ambarvm opened this issue Apr 28, 2024 · 1 comment · Fixed by #1319

Comments

@ambarvm
Copy link

ambarvm commented Apr 28, 2024

  • @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.

typeof React.act === 'function' ? React.act : DeprecatedReactTestUtils.act

But the types file always exports the type of deprecated act.
import {act as reactAct} from 'react-dom/test-utils'

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
@MatanBobi
Copy link
Member

Thanks @ambarvm, I've created #1319 to resolve this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants