Easily stub out IndexedDB
This mock is adapted from mock-indexeddb to play nice with CommonJS and npm
.
Use npm
.
npm i -D indexeddb-mock
A mock of the IndexedDB API.
Resets state in the mock. Call this before tests to reset state.
Adds an item with key
and value
. Used to prefill IndexedDB before tests.
You can set flags to determine what features are enabled. Here's the defaults.
{
"canOpenDB": true,
"openDBShouldBlock": false,
"openDBShouldAbort": false,
"upgradeNeeded": false,
"canReadDB": true,
"canSave": true,
"canDelete": true,
"canClear": true,
"canCreateStore": true,
"canDeleteDB": true
}
Note that flags are reset to their defaults whenever .reset()
is called.
MIT