Skip to content

Commit

Permalink
Remove act from around userEvent actions (#3295)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Aug 14, 2024
1 parent 5d7eee8 commit 25c5298
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 185 deletions.
128 changes: 21 additions & 107 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^14.3.1",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.2",
"@types/crypto-js": "^4.2.0",
"@types/css-mediaquery": "^0.1.2",
Expand Down
12 changes: 3 additions & 9 deletions src/components/PasswordReset/tests/Request.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ describe("ResetRequest", () => {

// Agent
const field = screen.getByTestId(PasswordRequestIds.FieldEmailOrUsername);
await act(async () => {
await agent.type(field, "a");
});
await agent.type(field, "a");

// After
expect(button).toBeEnabled();
Expand All @@ -74,12 +72,8 @@ describe("ResetRequest", () => {

// Agent
const field = screen.getByTestId(PasswordRequestIds.FieldEmailOrUsername);
await act(async () => {
await agent.type(field, "a");
});
await act(async () => {
await agent.click(screen.getByRole("button"));
});
await agent.type(field, "a");
await agent.click(screen.getByRole("button"));

// After
expect(
Expand Down
28 changes: 9 additions & 19 deletions src/components/PasswordReset/tests/ResetPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ describe("PasswordReset", () => {
PasswordResetTestIds.ConfirmPassword
);

await act(async () => {
await user.type(passwdField, shortPassword);
await user.type(passwdConfirm, shortPassword);
});
await user.type(passwdField, shortPassword);
await user.type(passwdConfirm, shortPassword);

const reqErrors = screen.queryAllByTestId(
PasswordResetTestIds.PasswordReqError
Expand All @@ -103,10 +101,8 @@ describe("PasswordReset", () => {
PasswordResetTestIds.ConfirmPassword
);

await act(async () => {
await user.type(passwdField, passwordEntry);
await user.type(passwdConfirm, confirmEntry);
});
await user.type(passwdField, passwordEntry);
await user.type(passwdConfirm, confirmEntry);

const reqErrors = screen.queryAllByTestId(
PasswordResetTestIds.PasswordReqError
Expand All @@ -132,10 +128,8 @@ describe("PasswordReset", () => {
PasswordResetTestIds.ConfirmPassword
);

await act(async () => {
await user.type(passwdField, passwordEntry);
await user.type(passwdConfirm, confirmEntry);
});
await user.type(passwdField, passwordEntry);
await user.type(passwdConfirm, confirmEntry);

const reqErrors = screen.queryAllByTestId(
PasswordResetTestIds.PasswordReqError
Expand All @@ -162,16 +156,12 @@ describe("PasswordReset", () => {
PasswordResetTestIds.ConfirmPassword
);

await act(async () => {
await user.type(passwdField, passwordEntry);
await user.type(passwdConfirm, confirmEntry);
});
await user.type(passwdField, passwordEntry);
await user.type(passwdConfirm, confirmEntry);

const submitButton = screen.getByTestId(PasswordResetTestIds.SubmitButton);
mockPasswordReset.mockResolvedValueOnce(false);
await act(async () => {
await user.click(submitButton);
});
await user.click(submitButton);

const resetErrors = screen.queryAllByTestId(
PasswordResetTestIds.PasswordResetFail
Expand Down
12 changes: 3 additions & 9 deletions src/components/ProjectSettings/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ describe("ProjectSettings", () => {
const tabs = Object.values(ProjectSettingsTab);
expect(screen.queryAllByRole("tab")).toHaveLength(tabs.length);
for (const tab of tabs) {
await act(async () => {
await agent.click(screen.getByTestId(tab));
});
await agent.click(screen.getByTestId(tab));
isPanelVisible(tab);
}
});
Expand All @@ -145,9 +143,7 @@ describe("ProjectSettings", () => {
const tabs = whichTabs(perm, hasSchedule);
expect(screen.queryAllByRole("tab")).toHaveLength(tabs.length);
for (const tab of tabs) {
await act(async () => {
await agent.click(screen.getByTestId(tab));
});
await agent.click(screen.getByTestId(tab));
whichSettings(perm, hasSchedule, tab).forEach((s) =>
screen.getByTestId(s)
);
Expand All @@ -166,9 +162,7 @@ describe("ProjectSettings", () => {
const tabs = whichTabs(perm, hasSchedule);
expect(screen.queryAllByRole("tab")).toHaveLength(tabs.length);
for (const tab of tabs) {
await act(async () => {
await agent.click(screen.getByTestId(tab));
});
await agent.click(screen.getByTestId(tab));
whichSettings(perm, hasSchedule, tab).forEach((s) =>
screen.getByTestId(s)
);
Expand Down
12 changes: 3 additions & 9 deletions src/components/SiteSettings/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,15 @@ describe("SiteSettings", () => {
await renderSiteSettings();

// Banners tab
await act(async () => {
await agent.click(screen.getByTestId(SiteSettingsTab.Banners));
});
await agent.click(screen.getByTestId(SiteSettingsTab.Banners));
isPanelVisible(SiteSettingsTab.Banners);

// Projects tab
await act(async () => {
await agent.click(screen.getByTestId(SiteSettingsTab.Projects));
});
await agent.click(screen.getByTestId(SiteSettingsTab.Projects));
isPanelVisible(SiteSettingsTab.Projects);

// Users tab
await act(async () => {
await agent.click(screen.getByTestId(SiteSettingsTab.Users));
});
await agent.click(screen.getByTestId(SiteSettingsTab.Users));
isPanelVisible(SiteSettingsTab.Users);
});
});
8 changes: 2 additions & 6 deletions src/components/TreeView/tests/TreeSearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ describe("TreeSearch", () => {
render(<TreeSearch {...testProps} />);
expect(getSearchInput().value).toEqual("");
const searchText = "flibbertigibbet";
await act(async () => {
await userEvent.type(getSearchInput(), `${searchText}{enter}`);
});
await userEvent.type(getSearchInput(), `${searchText}{enter}`);
expect(getSearchInput().value).toEqual(searchText);
// verify that no attempt to switch domains happened
expect(MOCK_ANIMATE).toHaveBeenCalledTimes(0);
Expand All @@ -124,9 +122,7 @@ describe("TreeSearch", () => {
render(<TreeSearch {...testProps} />);
expect(getSearchInput().value).toEqual("");
setupSpies(domMap[mapIds.lastKid]);
await act(async () => {
await userEvent.type(getSearchInput(), `${mapIds.lastKid}{enter}`);
});
await userEvent.type(getSearchInput(), `${mapIds.lastKid}{enter}`);
expect(getSearchInput().value).toEqual("");
// verify that we would switch to the domain requested
expect(MOCK_ANIMATE).toHaveBeenCalledWith(domMap[mapIds.lastKid]);
Expand Down
Loading

0 comments on commit 25c5298

Please sign in to comment.