| 9 | import { mockFetch } from "./mocks/fetch"; |
| 10 | |
| 11 | function createStorageMock(): Storage { |
| 12 | const store = new Map<string, string>(); |
| 13 | return new Proxy( |
| 14 | { |
| 15 | getItem: (k: string) => store.get(k) ?? null, |
| 16 | setItem: (k: string, v: string) => void store.set(String(k), String(v)), |
| 17 | removeItem: (k: string) => void store.delete(k), |
| 18 | clear: () => store.clear(), |
| 19 | key: (i: number) => [...store.keys()][i] ?? null, |
| 20 | } as Storage, |
| 21 | { |
| 22 | get: (t, p) => (p === "length" ? store.size : p in t ? (t as any)[p] : store.get(p as string)), |
| 23 | set: (t, p, v) => (p in t ? false : (store.set(p as string, String(v)), true)), |
| 24 | deleteProperty: (_, p) => store.delete(p as string), |
| 25 | has: (t, p) => p in t || p === "length" || store.has(p as string), |
| 26 | ownKeys: () => [...store.keys()], |
| 27 | getOwnPropertyDescriptor: (_, p) => |
| 28 | store.has(p as string) |
| 29 | ? { value: store.get(p as string), writable: true, enumerable: true, configurable: true } |
| 30 | : undefined, |
| 31 | } |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | // Ensure localStorage exists |
| 36 | if (typeof window !== "undefined" && !global.localStorage?.getItem) { |