Update frontends/nextjs/src/hooks/data/__tests__/useKV.validation.test.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
2025-12-29 16:09:33 +00:00
committed by GitHub
parent 8012fe13ec
commit 0dfba0bc83

View File

@@ -5,27 +5,23 @@ import { useKV } from '@/hooks/data/useKV'
const STORAGE_PREFIX = 'mb_kv:'
let store: Record<string, string>
const setupLocalStorage = (): void => {
store = {}
vi.stubGlobal('localStorage', {
getItem: vi.fn((key: string) => store[key] ?? null),
setItem: vi.fn((key: string, value: string) => {
store[key] = value
}),
removeItem: vi.fn((key: string) => {
delete store[key]
}),
clear: vi.fn(() => {
Object.keys(store).forEach(k => delete store[k])
}),
length: 0,
key: vi.fn(() => null),
})
}
describe('useKV validation', () => {
beforeEach(() => {
setupLocalStorage()
store = {}
vi.stubGlobal('localStorage', {
getItem: vi.fn((key: string) => store[key] ?? null),
setItem: vi.fn((key: string, value: string) => {
store[key] = value
}),
removeItem: vi.fn((key: string) => {
delete store[key]
}),
clear: vi.fn(() => {
Object.keys(store).forEach(k => delete store[k])
}),
length: 0,
key: vi.fn(() => null),
})
})
it.each([