A mock implementation of the Cache API (Cache, CacheStorage) for Node.js testing environments. Version 0.1.7 provides an in-memory cache for testing browser caching strategies without a browser. It ships TypeScript types and is designed for use with test frameworks like Jest or Mocha. This package allows mocking the Cache API to verify cached response behavior, such as offline support or cache-first strategies. The library is minimal and focused, with no external runtime dependencies, and is primarily maintained by MechanicalRock.
npm install browser-cache-mockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to instantiate CacheMock, mock global caches, and use put/match for testing browser cache strategies.
Do not rely on CacheMock for testing cache quota behavior; use browser-based tests for that.
Review the unsupported features: some CacheStorage methods may be missing or not fully implemented.
Check the latest spec additions (e.g., CacheStorage.keys) and implement custom mocks if needed.
Use import CacheMock from 'browser-cache-mock' (ESM) or const CacheMock = require('browser-cache-mock').default (CJS).Set moduleResolution to 'node16' or 'nodenext' in tsconfig.json and ensure the package is installed.
Use default import: import CacheMock from 'browser-cache-mock'.
No dependency data recorded yet.