Closed
Description
Reproduction example
https://github.com/mikaelrss/rhf-rtl-act-bug-repro
Prerequisites
git clone [email protected]: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/[email protected]
but breaks in @testing-library/[email protected]
User-event version
14.1.1
Environment
Testing Library framework: @testing-library/[email protected]
JS framework: [email protected]
and [email protected]
Test environment: [email protected]
which uses [email protected]
Additional context
Working version on main
branch of repro is @testing-library/[email protected]