Skip to content

Wrap waitFor with async act #343

@thymikee

Description

@thymikee

Describe the Feature

React batches updates to the underlying native platform using act helper. We already use that for sync calls to render, update and fireEvent. However, it's common to put side effects updating React component state inside useEffect. Doing that will produce the dreaded "updates should be wrapped into act(...)" warning. To account for that, React introduced async version of act in v16.9.

So, to avoid our users wrap their waitFor and findBy queries with async act(), we can wrap waitFor callback with an async act, so it's done automatically, removing churn when testing React.

Possible Implementations

If we bump the minimum required React version to 16.9, it should be as easy as wrapping wait for with async act. However, if we want to provide compatibility with older React versions, we'll need to come up with a workaround, because IIRC act in React 16.8 yells if you try to use it in non-sync way

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