-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
22 lines (21 loc) · 1.07 KB
/
Copy pathvitest.setup.ts
File metadata and controls
22 lines (21 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import "@testing-library/jest-dom";
import "fake-indexeddb/auto";
// Node 25 ships a native `localStorage` that has no backing store unless
// --localstorage-file is provided. Zustand's persist middleware captures
// `window.localStorage` at module-load time, so it ends up with this broken
// native object instead of jsdom's working implementation.
// Replace it with a simple in-memory stub so persist-backed stores work in tests.
const _localStorageStore: Record<string, string> = {};
const _localStorageStub: Storage = {
getItem: (key: string) => _localStorageStore[key] ?? null,
setItem: (key: string, value: string) => { _localStorageStore[key] = value; },
removeItem: (key: string) => { delete _localStorageStore[key]; },
clear: () => { Object.keys(_localStorageStore).forEach((k) => delete _localStorageStore[k]); },
get length() { return Object.keys(_localStorageStore).length; },
key: (i: number) => Object.keys(_localStorageStore)[i] ?? null,
};
Object.defineProperty(globalThis, "localStorage", {
value: _localStorageStub,
writable: true,
configurable: true,
});