diff --git a/test/test.browser.ts b/test/test.browser.ts index a74c863..7ae8973 100644 --- a/test/test.browser.ts +++ b/test/test.browser.ts @@ -11,10 +11,6 @@ tap.test('first test', async () => { expect(testWebstore).to.be.instanceOf(webstore.WebStore); }); -tap.test('should init the database', async () => { - await testWebstore.init(); -}); - tap.test('should allow storing a string', async () => { await testWebstore.set('mystring', 'heythere'); expect(await testWebstore.get('mystring')).to.equal('heythere'); diff --git a/ts/webstore.classes.webstore.ts b/ts/webstore.classes.webstore.ts index 5c62e3d..4d25681 100644 --- a/ts/webstore.classes.webstore.ts +++ b/ts/webstore.classes.webstore.ts @@ -18,7 +18,8 @@ export class WebStore { public async init() { if (this.initCalled) { - return this.readyDeferred.promise; + await this.readyDeferred.promise; + return; } this.initCalled = true; this.db = await plugins.idb.openDB(this.options.dbName, 1, { @@ -27,6 +28,7 @@ export class WebStore { }, }); this.readyDeferred.resolve(); + return; } async get(key: string): Promise { @@ -41,6 +43,7 @@ export class WebStore { } async set(key: string, val: T) { + await this.init(); return this.db.put(this.options.storeName, val, key); }