A lightweight in-memory mock implementation of the Web Storage API (Storage interface) for testing. Version 1.1.0. Fully compliant with TypeScript's Storage interface, uses ES2015 Proxy and Map. Ideal for unit testing localStorage/sessionStorage in Node.js or browser environments without side effects. Differentiates from alternatives like jest-localstorage-mock by being pure TypeScript with a simple API.
npm install mock-storageNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating a mock storage instance, setting/getting items, using property access, TypeScript type, and initializing with data.
Use explicit setItem/getItem methods instead of property access, or ensure Proxy polyfill is available.
Use import syntax or configure your test framework to support ESM (e.g., use --experimental-vm-modules in Node, or transform in Jest).
To add to existing data, pass a Map containing the desired initial entries.
Replace require with import: import { mockStorage } from 'mock-storage'Use setItem/getItem instead: storage.setItem('foo', 'bar')Use type-only import: import type { Storage } from 'mock-storage'No dependency data recorded yet.