-
Notifications
You must be signed in to change notification settings - Fork 36
/
idb-store.test.ts
39 lines (32 loc) · 967 Bytes
/
idb-store.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {runAll, TestStore} from './store-test-util';
import {dropStore, IDBStore} from './idb-store';
import {expect} from '@esm-bundle/chai';
async function newRandomIDBStore() {
const name = `test-idbstore-${Math.random()}`;
await dropStore(name);
return new IDBStore(name);
}
runAll('idbstore', newRandomIDBStore);
test('dropStore', async () => {
const name = `drop-store-${Math.random()}`;
await dropStore(name);
let idb = new IDBStore(name);
let store = new TestStore(idb);
// Write a value.
await store.withWrite(async wt => {
await wt.put('foo', 'bar');
await wt.commit();
});
// Verify it's there.
await store.withRead(async rt => {
expect(await rt.get('foo')).to.deep.equal('bar');
});
// Drop db
await dropStore(name);
// Reopen store, verify data is gone
idb = new IDBStore(name);
store = new TestStore(idb);
await store.withRead(async rt => {
expect(await rt.has('foo')).to.be.false;
});
});