Stub (window.)location (#34041)
* Stub (window.)location As per comment * avoid sonar's trigger word
This commit is contained in:
@@ -15,10 +15,15 @@ vi.stubGlobal("AudioContext", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (globalThis.window === undefined) {
|
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", {
|
vi.stubGlobal("window", {
|
||||||
// Mock this as some code assumes it exists (needs to be done at the top level as
|
// 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)
|
// things try to access it before the beforeEach blocks run)
|
||||||
addEventListener: vi.fn(),
|
addEventListener: vi.fn(),
|
||||||
|
location: locationStub,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user