Skip to content

Commit 075ee10

Browse files
authored
Remove act from around testing-library async clicks (#3856)
1 parent 0881512 commit 075ee10

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

src/components/Login/tests/Login.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { render, screen } from "@testing-library/react";
1+
import { act, render, screen } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
3-
import { act } from "react";
43
import { Provider } from "react-redux";
54
import configureMockStore from "redux-mock-store";
65

@@ -47,7 +46,7 @@ const typeInField = async (id: LoginId, value: string): Promise<void> => {
4746
/** Click the Login button and confirm whether the field with the given ID has an error. */
4847
const loginAndCheckError = async (errorId?: LoginId): Promise<void> => {
4948
// Login button click
50-
await act(async () => screen.getByTestId(LoginId.ButtonLogIn).click());
49+
await userEvent.click(screen.getByTestId(LoginId.ButtonLogIn));
5150

5251
// Username field check
5352
const userLabel = screen.getByText(LoginTextId.LabelUsername);

src/components/Login/tests/Signup.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { render, screen } from "@testing-library/react";
1+
import { act, render, screen } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
3-
import { act } from "react";
43
import { Provider } from "react-redux";
54
import configureMockStore from "redux-mock-store";
65

@@ -75,7 +74,7 @@ const typeInFields = async (textRecord: Partial<SignupText>): Promise<void> => {
7574
/** Clicks the submit button and checks that only the specified field errors. */
7675
const submitAndCheckError = async (id?: SignupField): Promise<void> => {
7776
// Submit the form.
78-
await act(async () => screen.getByTestId(SignupId.ButtonSignUp).click());
77+
await userEvent.click(screen.getByTestId(SignupId.ButtonSignUp));
7978

8079
// Only the specified field should error.
8180
Object.values(SignupField).forEach((val) => {

src/components/ProjectUsers/tests/SpeakerConsentListItemIcon.test.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ describe("SpeakerConsentListItemIcon", () => {
7979
expect(screen.queryByTestId(ListItemIconId.RecordAudio)).toBeNull();
8080
expect(screen.queryByTestId(ListItemIconId.UploadAudio)).toBeNull();
8181

82-
await act(async () => {
83-
await agent.click(screen.getByRole("button"));
84-
});
82+
await agent.click(screen.getByRole("button"));
8583
expect(screen.queryByRole("menu")).not.toBeNull();
8684
expect(screen.queryByTestId(ListItemIconId.RecordAudio)).not.toBeNull();
8785
expect(screen.queryByTestId(ListItemIconId.UploadAudio)).not.toBeNull();
@@ -119,9 +117,7 @@ describe("SpeakerConsentListItemIcon", () => {
119117
});
120118
expect(screen.queryByRole("dialog")).toBeNull();
121119

122-
await act(async () => {
123-
await agent.click(screen.getByRole("button"));
124-
});
120+
await agent.click(screen.getByRole("button"));
125121
expect(screen.queryByRole("dialog")).not.toBeNull();
126122
});
127123
});

0 commit comments

Comments
 (0)