From f289735da9e4a3cee7960430df4945983f6be2ae Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 21 Jan 2026 14:08:23 -0600 Subject: [PATCH] Fix tests by mocking the localStorage API --- src/test/setup.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/test/setup.ts b/src/test/setup.ts index 149f83cb..b5e1f465 100644 --- a/src/test/setup.ts +++ b/src/test/setup.ts @@ -1,6 +1,39 @@ import '@testing-library/jest-dom'; import { vi } from 'vitest'; +// Mock localStorage for Node.js 25 compatibility +// Node.js 25 provides a localStorage object but it's incomplete without --localstorage-file +// We override it with a proper mock that implements the full Storage interface +class LocalStorageMock implements Storage { + private store: Map = new Map(); + + clear(): void { + this.store.clear(); + } + + getItem(key: string): string | null { + return this.store.get(key) ?? null; + } + + setItem(key: string, value: string): void { + this.store.set(key, value); + } + + removeItem(key: string): void { + this.store.delete(key); + } + + get length(): number { + return this.store.size; + } + + key(index: number): string | null { + return Array.from(this.store.keys())[index] ?? null; + } +} + +global.localStorage = new LocalStorageMock(); + // Mock CSS imports vi.mock('*.css', () => ({})); vi.mock('*.scss', () => ({}));