Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix: mock localStorage in test setup for Zustand persist middleware

Pouzor923f0c0c2202
diff --git a/frontend/src/stores/__tests__/authStore.test.ts b/frontend/src/stores/__tests__/authStore.test.ts
index fa16eab..b44e453 100644
--- a/frontend/src/stores/__tests__/authStore.test.ts
+++ b/frontend/src/stores/__tests__/authStore.test.ts
@@ -3,6 +3,7 @@ import { useAuthStore } from '@/stores/authStore'
describe('authStore', () => {
beforeEach(() => {
+ localStorage.clear()
useAuthStore.setState({ token: null, isAuthenticated: false })
})
diff --git a/frontend/src/test/setup.ts b/frontend/src/test/setup.ts
index c44951a..0fa7bfd 100644
--- a/frontend/src/test/setup.ts
+++ b/frontend/src/test/setup.ts
@@ -1 +1,14 @@
import '@testing-library/jest-dom'
+
+// Zustand persist middleware requires localStorage. jsdom provides it but
+// some test runners strip it — ensure a working implementation is always present.
+const store: Record<string, string> = {}
+Object.defineProperty(globalThis, 'localStorage', {
+ value: {
+ getItem: (k: string) => store[k] ?? null,
+ setItem: (k: string, v: string) => { store[k] = v },
+ removeItem: (k: string) => { delete store[k] },
+ clear: () => { Object.keys(store).forEach((k) => delete store[k]) },
+ },
+ writable: true,
+})