forked from Dshield-xyz/Dshield
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-setup.ts
More file actions
30 lines (26 loc) · 864 Bytes
/
Copy pathtest-setup.ts
File metadata and controls
30 lines (26 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { beforeEach } from "vitest";
const storage = new Map<string, string>();
Object.defineProperty(globalThis, "localStorage", {
value: {
getItem: (key: string) => storage.get(key) ?? null,
setItem: (key: string, value: string) => storage.set(key, value),
removeItem: (key: string) => storage.delete(key),
clear: () => storage.clear(),
},
writable: true,
});
// Define window so typeof window !== "undefined" guards pass in tests
if (typeof globalThis.window === "undefined") {
(globalThis as Record<string, unknown>).window = globalThis;
}
if (typeof (globalThis.window as { location?: unknown }).location === "undefined") {
(globalThis.window as unknown as Record<string, unknown>).location = {
origin: "https://dshield.test",
hash: "",
pathname: "/",
search: "",
};
}
beforeEach(() => {
storage.clear();
});