15
15
* limitations under the License.
16
16
*/
17
17
18
+ import * as sinon from 'sinon' ;
18
19
import { PersistenceType } from '.' ;
19
20
import { expect } from 'chai' ;
20
21
import { indexedDBLocalPersistence as persistence } from './indexed_db' ;
21
22
import { User } from '../../model/user' ;
22
23
import { testUser } from '../../../test/mock_auth' ;
23
24
24
25
describe ( 'core/persistence/indexed_db' , ( ) => {
26
+ afterEach ( sinon . restore ) ;
27
+
25
28
it ( 'should work with persistence type' , async ( ) => {
26
29
const key = 'my-super-special-persistence-type' ;
27
30
const value = PersistenceType . LOCAL ;
@@ -46,4 +49,24 @@ describe('core/persistence/indexed_db', () => {
46
49
await persistence . remove ( key ) ;
47
50
expect ( await persistence . get ( key ) ) . to . be . null ;
48
51
} ) ;
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
+ } ) ;
49
71
} ) ;
72
+
0 commit comments