Skip to content

Update of the @testing-library/react version to 14.0.0 throws "act" warnings #1104

Closed
@maive1

Description

@maive1
  • @testing-library/react version: 14.0.0
  • Testing Framework and version: jest 29.4.2
  • DOM Environment: @testing-library/jest-dom: 5.16.5

Relevant code or config:

   const saveButton = screen.getByRole('button', { name: /save/i });
    await waitFor(() => expect(saveButton).toBeEnabled());
    await testUser.click(saveButton);

What you did:

I upgraded the version of @testing-library/react from 13.4.0 to 14.0.0. And I started having problems in all the tests of my application. Before this update this did not happen.

What happened:

I'm getting more act warnings now with @testing-library@14.0.0.
Tested with await waitFor, and still throwing act warnings with userEvent that triggers a state change.
Captura de Pantalla 2023-02-20 a la(s) 18 29 41
Captura de Pantalla 2023-02-20 a la(s) 18 29 13

Reproduction:

You can fork to reproduce the issue:
here: https://codesandbox.io/s/act-warning-wait-for-react-18-forked-6jurf2

Problem description:

The state update (setState()) seems to make the test library think that act is incomplete, even though it is. This happens for every unit test where an event is fired, such as userEvent.click() or userEvent.upload().

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