-
Notifications
You must be signed in to change notification settings - Fork 254
Closed
Labels
Description
Reproduction example
https://github.com/mikaelrss/rhf-rtl-act-bug-repro
Prerequisites
git clone git@github.com:mikaelrss/rhf-rtl-act-bug-repro.git
cd rhf-act-bug-repro
yarn install
yarn test
--> See that the tests pass without any act warnings.git checkout user-event@14
yarn install
yarn test
--> See that the tests pass but now with an act warning.
Expected behavior
I expect that the test below passes without any act warnings.
it("should show an error message when title field is cleared", async () => {
render(<Form />);
expect(screen.queryByText("Title is required")).not.toBeInTheDocument();
await userEvent.clear(screen.getByLabelText("Title"));
expect(await screen.findByText("Title is required")).toBeInTheDocument();
});
Actual behavior
The following test produces an act warning.
it("should show an error message when title field is cleared", async () => {
render(<Form />);
expect(screen.queryByText("Title is required")).not.toBeInTheDocument();
await userEvent.clear(screen.getByLabelText("Title"));
expect(await screen.findByText("Title is required")).toBeInTheDocument();
});
Wrapping the await userEvent.clear(screen.getByLabelText("Title"))
in an act
removes the warning.
it("should show an error message when title field is cleared", async () => {
render(<Form />);
expect(screen.queryByText("Title is required")).not.toBeInTheDocument();
await act(async () => {
await userEvent.clear(screen.getByLabelText("Title"));
});
expect(await screen.findByText("Title is required")).toBeInTheDocument();
});
This works as expected with @testing-library/user-event@13.2.1
but breaks in @testing-library/user-event@14.1.1
User-event version
14.1.1
Environment
Testing Library framework: @testing-library/react@13.0.0
JS framework: react@18.0.0
and react-hook-form@7.30.0
Test environment: react-scripts@5.0.1
which uses jest@27.5.1
Additional context
Working version on main
branch of repro is @testing-library/user-event@13.2.1
magnattic