Skip to content

Commit 3ca8343

Browse files
committed
Add indexed_db isAvailable test
1 parent 0467aa1 commit 3ca8343

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages-exp/auth-exp/src/core/persistence/indexed_db.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
* limitations under the License.
1616
*/
1717

18+
import * as sinon from 'sinon';
1819
import { PersistenceType } from '.';
1920
import { expect } from 'chai';
2021
import { indexedDBLocalPersistence as persistence } from './indexed_db';
2122
import { User } from '../../model/user';
2223
import { testUser } from '../../../test/mock_auth';
2324

2425
describe('core/persistence/indexed_db', () => {
26+
afterEach(sinon.restore);
27+
2528
it('should work with persistence type', async () => {
2629
const key = 'my-super-special-persistence-type';
2730
const value = PersistenceType.LOCAL;
@@ -46,4 +49,24 @@ describe('core/persistence/indexed_db', () => {
4649
await persistence.remove(key);
4750
expect(await persistence.get(key)).to.be.null;
4851
});
52+
53+
describe('#isAvaliable', () => {
54+
it('should return true if db is available', async () => {
55+
expect(await persistence.isAvailable()).to.be.true;
56+
});
57+
58+
it('should return false if db creation errors', async () => {
59+
sinon.stub(indexedDB, 'open').returns({
60+
addEventListener(evt: string, cb: () => void) {
61+
if (evt === 'error') {
62+
cb();
63+
}
64+
},
65+
error: new DOMException('yes there was an error'),
66+
} as any);
67+
68+
expect(await persistence.isAvailable()).to.be.false;
69+
});
70+
});
4971
});
72+

0 commit comments

Comments
 (0)