All files / src/features/onboarding testStorage.ts

0% Statements 0/8
0% Branches 0/4
0% Functions 0/7
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20                                       
// jsdom here does not expose a working localStorage on file:// URLs (see
// StartSessionForm.test / round-preference.test). Install a minimal Map-backed
// Storage so dismissal assertions run against a real getItem/setItem round-trip.
export function installStorage() {
  const map = new Map<string, string>();
  Object.defineProperty(window, "localStorage", {
    value: {
      get length() {
        return map.size;
      },
      clear: () => map.clear(),
      getItem: (k: string) => (map.has(k) ? (map.get(k) as string) : null),
      setItem: (k: string, v: string) => void map.set(k, String(v)),
      removeItem: (k: string) => void map.delete(k),
      key: (i: number) => Array.from(map.keys())[i] ?? null,
    },
    configurable: true,
  });
}