MCPcopy
hub / github.com/simstudioai/sim / createMockStorage

Function createMockStorage

packages/testing/src/mocks/storage.mock.ts:13–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11 * ```
12 */
13export function createMockStorage(): Storage {
14 const store: Record<string, string> = {}
15
16 return {
17 getItem: vi.fn((key: string) => store[key] ?? null),
18 setItem: vi.fn((key: string, value: string) => {
19 store[key] = value
20 }),
21 removeItem: vi.fn((key: string) => {
22 delete store[key]
23 }),
24 clear: vi.fn(() => {
25 Object.keys(store).forEach((key) => delete store[key])
26 }),
27 key: vi.fn((index: number) => Object.keys(store)[index] ?? null),
28 get length() {
29 return Object.keys(store).length
30 },
31 }
32}
33
34/**
35 * Sets up global localStorage and sessionStorage mocks.

Callers 3

store.test.tsFile · 0.90
store.test.tsFile · 0.90
setupGlobalStorageMocksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected