Skip to content

no-unnecessary-act false positive for new React.act ?! #906

@florian-bretz-pt

Description

@florian-bretz-pt

What rule do you want to change?

no-unnecessary-act

Does this change cause the rule to produce more or fewer warnings?

More warnings

How will the change be implemented?

check if no-unnecessary-act rule applies correctly to the new act of react

Example code

Since the latest react release it seems to be necessary to wrap state changes with the new act of react:

 When testing, code that causes React state updates should be wrapped into act(...):
    
    act(() => {
      /* fire events that update state */
    });
    /* assert on the output */

Implementation:

import { act } from 'react'

await act(async () => {
    await userEvent.click(radioButton)
})

How does the current rule affect the code?

This is wrongful (?!) picked up by testing-library/no-unnecessary-act

How will the new rule affect the code?

if possible, consider act coming from react could be ignored

Anything else?

No response

Do you want to submit a pull request to change the rule?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttriagePending to be triaged by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions