Stub (window.)location (#34041)

* Stub (window.)location

As per comment

* avoid sonar's trigger word
This commit is contained in:
David Baker
2026-06-30 08:16:22 +00:00
committed by GitHub
parent 84c0d2c479
commit 1aa86110e2
+6 -1
View File
@@ -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,
});
}