webstore/test/test.browser.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-07-09 22:30:33 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
import * as webstore from '../ts/index';
2020-07-09 23:03:01 +00:00
let testWebstore: webstore.WebStore;
2020-07-09 22:30:33 +00:00
tap.test('first test', async () => {
2020-07-09 23:03:01 +00:00
testWebstore = new webstore.WebStore({
2020-07-11 17:15:24 +00:00
dbName: 'mytest-db',
2020-09-18 10:12:02 +00:00
storeName: 'mytest-store',
2020-07-09 23:03:01 +00:00
});
2020-07-09 22:30:33 +00:00
expect(testWebstore).to.be.instanceOf(webstore.WebStore);
});
2020-07-09 23:03:01 +00:00
tap.test('should init the database', async () => {
await testWebstore.init();
});
2020-07-11 17:19:29 +00:00
tap.test('should allow storing a string', async () => {
await testWebstore.set('mystring', 'heythere');
expect(await testWebstore.get('mystring')).to.equal('heythere');
});
tap.test('should allow storing an object', async () => {
2020-07-09 23:03:01 +00:00
await testWebstore.set('testProp1', {
2020-09-18 10:12:02 +00:00
wow: 'wowVal',
2020-07-09 23:03:01 +00:00
});
console.log(JSON.stringify(await testWebstore.get('testProp1')));
});
2020-07-11 17:15:24 +00:00
tap.test('should overwrite a value', async () => {
await testWebstore.set('testProp1', {
2020-09-18 10:12:02 +00:00
wow: 'wowVal2',
2020-07-11 17:15:24 +00:00
});
console.log(JSON.stringify(await testWebstore.get('testProp1')));
});
tap.test('should correctly check the existence of keys', async () => {
2020-09-18 10:12:02 +00:00
const resultNotThere = await testWebstore.check('notThere');
2020-07-11 17:15:24 +00:00
const resultThere = await testWebstore.check('testProp1');
expect(resultNotThere).to.be.false;
expect(resultThere).to.be.true;
});
2020-07-09 22:30:33 +00:00
tap.start();