From 1aa86110e290f3e38f7d052c9831be3f8d729ace Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 30 Jun 2026 09:16:22 +0100 Subject: [PATCH] Stub (window.)location (#34041) * Stub (window.)location As per comment * avoid sonar's trigger word --- apps/web/src/test/setupGlobals.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/web/src/test/setupGlobals.ts b/apps/web/src/test/setupGlobals.ts index 0867071bcc..f1cd3153d7 100644 --- a/apps/web/src/test/setupGlobals.ts +++ b/apps/web/src/test/setupGlobals.ts @@ -15,10 +15,15 @@ vi.stubGlobal("AudioContext", function () { }); if (globalThis.window === undefined) { - // We are in a node environment, stub a basic window so singletons work + // We are in a node environment, stub a basic window so singletons work. + // Also stub `location` as a bare global: some libraries (e.g. posthog toolbar) access + // `location` directly rather than via `window.location`. + const locationStub = new URL("test://test/test"); + vi.stubGlobal("location", locationStub); vi.stubGlobal("window", { // Mock this as some code assumes it exists (needs to be done at the top level as // things try to access it before the beforeEach blocks run) addEventListener: vi.fn(), + location: locationStub, }); }