Skip to content

Commit c682ef9

Browse files
authored
Merge pull request #9252 from Couchers-org/web/chore/upgrade-to-jest-30
chore: Update Jest to 30
2 parents 3f14101 + 6dfbca9 commit c682ef9

18 files changed

Lines changed: 1063 additions & 975 deletions

app/web/components/ImageInput/ImageInput.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("ImageInput component", () => {
9393
expect(uploadFileMock).toHaveBeenCalledTimes(1);
9494
});
9595

96-
expect(onSuccessMock).toBeCalledWith({
96+
expect(onSuccessMock).toHaveBeenCalledWith({
9797
file: MOCK_FILE,
9898
filename: MOCK_FILE.name,
9999
key: MOCK_KEY,

app/web/components/LocationAutocomplete/LocationAutocomplete.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("LocationAutocomplete component", () => {
8080
const submitButton = await screen.findByRole("button", { name: "submit" });
8181
await user.click(submitButton);
8282
await waitFor(() => {
83-
expect(submitAction).toBeCalledWith(
83+
expect(submitAction).toHaveBeenCalledWith(
8484
expect.objectContaining({
8585
location: {
8686
name: "test city, test county, test country",
@@ -171,7 +171,7 @@ describe("LocationAutocomplete component", () => {
171171
await user.click(submitButton);
172172

173173
await waitFor(() => {
174-
expect(submitAction).toBeCalledWith(
174+
expect(submitAction).toHaveBeenCalledWith(
175175
expect.objectContaining({
176176
location: "",
177177
}),
@@ -239,6 +239,6 @@ describe("LocationAutocomplete component", () => {
239239
expect(
240240
await screen.findByText(t("global:location_autocomplete.more_specific")),
241241
).toBeVisible();
242-
expect(submitAction).not.toBeCalled();
242+
expect(submitAction).not.toHaveBeenCalled();
243243
});
244244
});

app/web/features/analytics/provider.test.tsx

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ jest.mock("./eventCollector", () => ({
1616
let eventOnSpy: jest.SpyInstance;
1717
let eventOffSpy: jest.SpyInstance;
1818

19+
// jsdom makes window.location non-configurable, so it can't be replaced with
20+
// Object.defineProperty. pushState updates pathname/search/href in place instead.
21+
function setLocation(pathname: string, search = "") {
22+
window.history.pushState({}, "", `${pathname}${search}`);
23+
}
24+
1925
beforeEach(() => {
2026
mockLogEvent.mockReset();
2127
mockDestroyCollector.mockReset();
@@ -26,15 +32,7 @@ beforeEach(() => {
2632
// Reset router to root
2733
mockRouter.setCurrentUrl("/");
2834

29-
Object.defineProperty(window, "location", {
30-
value: {
31-
pathname: "/",
32-
search: "",
33-
href: "http://localhost/",
34-
},
35-
writable: true,
36-
configurable: true,
37-
});
35+
setLocation("/");
3836
});
3937

4038
afterEach(() => {
@@ -112,15 +110,10 @@ describe("AnalyticsProvider", () => {
112110

113111
describe("search property (item 9)", () => {
114112
it("includes non-UTM query params as search in initial page.viewed", () => {
115-
Object.defineProperty(window, "location", {
116-
value: {
117-
pathname: "/search",
118-
search: "?q=paris&guests=2&utm_source=google&utm_medium=cpc",
119-
href: "http://localhost/search?q=paris&guests=2&utm_source=google&utm_medium=cpc",
120-
},
121-
writable: true,
122-
configurable: true,
123-
});
113+
setLocation(
114+
"/search",
115+
"?q=paris&guests=2&utm_source=google&utm_medium=cpc",
116+
);
124117

125118
render(
126119
<AnalyticsProvider>
@@ -136,15 +129,7 @@ describe("AnalyticsProvider", () => {
136129
});
137130

138131
it("sets search to null when only UTM params are present", () => {
139-
Object.defineProperty(window, "location", {
140-
value: {
141-
pathname: "/landing",
142-
search: "?utm_source=google&utm_campaign=spring",
143-
href: "http://localhost/landing?utm_source=google&utm_campaign=spring",
144-
},
145-
writable: true,
146-
configurable: true,
147-
});
132+
setLocation("/landing", "?utm_source=google&utm_campaign=spring");
148133

149134
render(
150135
<AnalyticsProvider>
@@ -176,15 +161,10 @@ describe("AnalyticsProvider", () => {
176161

177162
describe("UTM params in session.started", () => {
178163
it("includes UTM params in session.started properties", () => {
179-
Object.defineProperty(window, "location", {
180-
value: {
181-
pathname: "/",
182-
search: "?utm_source=twitter&utm_medium=social&utm_campaign=launch",
183-
href: "http://localhost/?utm_source=twitter&utm_medium=social&utm_campaign=launch",
184-
},
185-
writable: true,
186-
configurable: true,
187-
});
164+
setLocation(
165+
"/",
166+
"?utm_source=twitter&utm_medium=social&utm_campaign=launch",
167+
);
188168

189169
render(
190170
<AnalyticsProvider>

app/web/features/auth/signup/CommunityGuidelinesForm.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ describe("community guidelines signup form", () => {
6969

7070
checkboxes.forEach(async (checkbox) => {
7171
expect(button).toBeDisabled();
72-
expect(signupFlowCommunityGuidelinesMock).not.toBeCalled();
72+
expect(signupFlowCommunityGuidelinesMock).not.toHaveBeenCalled();
7373
await user.click(checkbox);
7474
});
7575
await waitFor(() => expect(button).not.toBeDisabled());
7676
await user.click(button);
7777

7878
await waitFor(() => {
79-
expect(signupFlowCommunityGuidelinesMock).toBeCalledWith(
79+
expect(signupFlowCommunityGuidelinesMock).toHaveBeenCalledWith(
8080
"dummy-token",
8181
true,
8282
);

app/web/features/auth/signup/Signup.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ describe("Signup", () => {
594594
expect(
595595
await screen.findByLabelText(t("auth:account_form.username.field_label")),
596596
).toBeVisible();
597-
expect(signupFlowEmailTokenMock).toBeCalledWith("fakeEmailToken");
597+
expect(signupFlowEmailTokenMock).toHaveBeenCalledWith("fakeEmailToken");
598598
const { result } = renderHook(() => useAuthStore(), { wrapper });
599599
expect(result.current.authState.flowState?.needVerifyEmail).toBe(false);
600600
});

app/web/features/communities/discussions/DiscussionPage.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ describe("Discussion page", () => {
364364
);
365365

366366
await waitFor(() => {
367-
expect(mockRouter.back).toBeCalled();
367+
expect(mockRouter.back).toHaveBeenCalled();
368368
});
369369
});
370370

app/web/features/messages/groupchats/GroupChatView.test.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,10 @@ describe("GroupChatView", () => {
449449
screen.getByText(t("messages:chat_view.mute.unmute_button_label")).click();
450450

451451
await waitFor(() => {
452-
expect(muteChatMock).toBeCalledWith({ groupChatId: 1, unmute: true });
452+
expect(muteChatMock).toHaveBeenCalledWith({
453+
groupChatId: 1,
454+
unmute: true,
455+
});
453456
expect(muteIcon).not.toBeVisible();
454457
});
455458
});
@@ -482,7 +485,10 @@ describe("GroupChatView", () => {
482485
.click();
483486

484487
await waitFor(() => {
485-
expect(muteChatMock).toBeCalledWith({ groupChatId: 1, forever: true });
488+
expect(muteChatMock).toHaveBeenCalledWith({
489+
groupChatId: 1,
490+
forever: true,
491+
});
486492
});
487493

488494
// Manually update the query data to reflect the muted state

app/web/features/messages/requests/MarkAllReadButton.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ describe("MarkAllReadButton", () => {
9393
);
9494

9595
await waitFor(() => {
96-
expect(markLastSeenGroupChatMock).toBeCalledTimes(1);
97-
expect(markLastSeenGroupChatMock).toBeCalledWith(2, 2);
96+
expect(markLastSeenGroupChatMock).toHaveBeenCalledTimes(1);
97+
expect(markLastSeenGroupChatMock).toHaveBeenCalledWith(2, 2);
9898
expect(mutableStore).toMatchObject({
9999
chats: [
100100
{ lastSeenMessageId: 1 },
@@ -115,8 +115,8 @@ describe("MarkAllReadButton", () => {
115115
);
116116

117117
await waitFor(() => {
118-
expect(markLastRequestSeenMock).toBeCalledTimes(1);
119-
expect(markLastRequestSeenMock).toBeCalledWith(2, 2);
118+
expect(markLastRequestSeenMock).toHaveBeenCalledTimes(1);
119+
expect(markLastRequestSeenMock).toHaveBeenCalledWith(2, 2);
120120
expect(mutableStore).toMatchObject({
121121
requests: [
122122
{ lastSeenMessageId: 1 },

app/web/features/notifications/PushNotificationSettings.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const mockServiceWorker = {
5252

5353
describe("PushNotificationSettings Component", () => {
5454
const originalNavigator = global.navigator;
55-
const originalWindow = global.window;
5655

5756
const mNotification = jest.fn();
5857
Object.defineProperty(global, "Notification", {
@@ -73,10 +72,6 @@ describe("PushNotificationSettings Component", () => {
7372
value: originalNavigator,
7473
configurable: true,
7574
});
76-
Object.defineProperty(global, "window", {
77-
value: originalWindow,
78-
configurable: true,
79-
});
8075

8176
jest.resetAllMocks();
8277
});

app/web/features/profile/edit/EditProfilePage.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ describe("Edit profile", () => {
7878

7979
await user.clear(aboutMeInput);
8080
await waitFor(() => expect(aboutMeInput).toHaveValue(""));
81-
await user.type(aboutMeInput, aboutMeText);
81+
// Use paste instead of type for large text - much faster, avoids a
82+
// re-render of the whole form per keystroke
83+
await user.click(aboutMeInput);
84+
await user.paste(aboutMeText);
8285

8386
const saveButton = await screen.findByRole("button", {
8487
name: t("global:save_changes"),

0 commit comments

Comments
 (0)