Registry / testing / fake-storage

fake-storage

JSON →
library2.1.0jsnpmunverified

In-memory implementation of the Web Storage API (localStorage/sessionStorage) for testing and server-side environments. v2.1.0, stable and maintained. Lightweight with zero dependencies, mirrors the browser Storage interface exactly. Unlike other storage shims, this is purely memory-based with no persistence, making it ideal for unit tests. Ships as CommonJS only, no TypeScript definitions.

npm install fake-storage
INSTALL
IMPORT
SIG · FAKE-STORAGE
F
fake-storage
testingjavascriptv2.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FakeStorage
const FakeStorage = require('fake-storage')
import FakeStorage from 'fake-storage'
CommonJS only; ESM import not supported in v2.x.
FakeStorage (ESM)
import FakeStorage from 'fake-storage'
No official ESM export; CJS require is correct.
new FakeStorage()
const store = new FakeStorage()
const store = FakeStorage()
Must use 'new' to instantiate.

Create a FakeStorage instance and demonstrate basic setItem, getItem, length, key, and removeItem usage.

const FakeStorage = require('fake-storage'); const storage = new FakeStorage(); storage.setItem('key', 'value'); console.log(storage.getItem('key')); // 'value' console.log(storage.length); // 1 console.log(storage.key(0)); // 'key' storage.removeItem('key'); console.log(storage.length); // 0
Debug
Known issues
gotchaFakeStorage does not persist data across process restarts.
fix
Data is lost on process exit; do not use as a persistent store.
affects: >=1.0.0
gotchaFakeStorage does not emit events (no 'storage' event).
fix
It is a minimal shim; use window.addEventListener if browser storage events are needed.
affects: >=1.0.0
gotchaFakeStorage does not enforce size limits (unlike localStorage which is ~5MB).
fix
Be aware that unlimited growth may occur in long-running processes.
affects: >=1.0.0
gotchaFakeStorage does not handle Proxy or prototype pollution unlike some polyfills.
fix
Use only for explicit method calls; avoid direct property assignment.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: FakeStorage is not a constructor
Forgetting 'new' when instantiating.
fix
Use 'new FakeStorage()' instead of 'FakeStorage()'.
Cannot find module 'fake-storage'
Package not installed or import path wrong.
fix
Run 'npm install fake-storage' and use 'require('fake-storage')'.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fake-storage — npm install fake-storage · libregistry