Skip to content

Commit 9d94cf0

Browse files
committed
Fix LoginForm test to use window.location.href for query params
While window.history.replaceState should work with vitest-location-mock, it doesn't actually update window.location in practice. Setting window.location.href directly does work and properly updates window.location.search for the component to read during setup.
1 parent ae6e48f commit 9d94cf0

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

client/src/components/Login/LoginForm.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,17 @@ describe("LoginForm", () => {
158158
});
159159

160160
it("renders message from query params", async () => {
161-
const originalUrl = window.location.href;
162-
window.history.replaceState(null, "", "/login/start?message=auth-error&status=info");
161+
const originalHref = window.location.href;
162+
window.location.href = `${window.location.origin}/login/start?message=auth-error&status=info`;
163163

164164
const wrapper = await mountLoginForm();
165+
await flushPromises();
165166

166167
const alert = wrapper.find(".alert");
167168
expect(alert.exists()).toBe(true);
168169
expect(alert.text()).toContain("auth-error");
169170
expect(alert.classes()).toContain("alert-info");
170171

171-
window.history.replaceState(null, "", originalUrl);
172+
window.location.href = originalHref;
172173
});
173174
});

0 commit comments

Comments
 (0)