Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
// jsdom does not reliably expose `localStorage` across environments (e.g. on
// Node 26 its experimental built-in `localStorage` shadows the jsdom one, so
// `localStorage` is undefined in tests). Provide a minimal in-memory shim so
// tests that rely on `localStorage` run consistently regardless of the runtime.
if (typeof globalThis.localStorage === 'undefined') {
class MemoryStorage {
private store = new Map<string, string>();

get length(): number {
return this.store.size;
}

key(index: number): string | null {
return Array.from(this.store.keys())[index] ?? null;
}

getItem(key: string): string | null {
return this.store.get(key) ?? null;
}

setItem(key: string, value: string): void {
this.store.set(key, String(value));
}

removeItem(key: string): void {
this.store.delete(key);
}

clear(): void {
this.store.clear();
}
}

const storage = new MemoryStorage();
globalThis.localStorage = storage as unknown as Storage;
if (typeof window !== 'undefined') {
window.localStorage = storage as unknown as Storage;
}
}

beforeEach(() => {
if (typeof localStorage !== 'undefined') {
localStorage.clear();
Expand Down
Loading