diff --git a/indexeddb.js b/indexeddb.js index 861a6f6..90316d4 100644 --- a/indexeddb.js +++ b/indexeddb.js @@ -38,7 +38,9 @@ export const openDB = (name, initDB) => globals.createPromise((resolve, reject) request.onsuccess = event => { const db = event.target.result db.onversionchange = () => { db.close() } - addEventListener('unload', () => db.close()) + if (typeof addEventListener !== 'undefined') { + addEventListener('unload', () => db.close()) + } resolve(db) } }) diff --git a/indexeddb.test.js b/indexeddb.test.js index ae8cb70..452230b 100644 --- a/indexeddb.test.js +++ b/indexeddb.test.js @@ -3,6 +3,13 @@ import * as idb from './indexeddb.js' import * as environment from './environment.js' import * as promise from './promise.js' +if (environment.isNode) { + // @ts-ignore + global.indexedDB = require('fake-indexeddb') + // @ts-ignore + global.IDBKeyRange = require('fake-indexeddb/lib/FDBKeyRange') +} + const initTestDB = db => idb.createStores(db, [['test']]) const testDBName = 'idb-test' @@ -14,7 +21,6 @@ const createTransaction = db => db.transaction(['test'], 'readwrite') const getStore = t => idb.getStore(t, 'test') export const testIdbIteration = async () => { - t.skip(!environment.isBrowser) t.describe('create, then iterate some keys') await idb.deleteDB(testDBName) const db = await idb.openDB(testDBName, initTestDB) @@ -37,7 +43,6 @@ export const testIdbIteration = async () => { } export const testIdbIterationNoAwait = () => { - t.skip(!environment.isBrowser) t.describe('create, then iterate some keys') return idb.deleteDB(testDBName) .then(() => idb.openDB(testDBName, initTestDB)) diff --git a/package.json b/package.json index 49714ac..764c924 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "", "dependencies": {}, "devDependencies": { + "fake-indexeddb": "^2.0.5", "live-server": "^1.2.1", "nyc": "^13.3.0", "rollup": "^1.1.2",