Skip to content

act shows up as deprecated when using react 18.3 #1316

Closed
@ambarvm

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions