@@ -299,7 +299,7 @@ describe('persisted()', () => {
299
299
expect ( await localforage . getItem ( "myKey11" ) ) . toEqual ( serializer . stringify ( new Set ( [ 1 , 2 , 3 , 4 ] ) ) )
300
300
} )
301
301
302
- it ( 'lets you switch storage type' , ( ) => {
302
+ it ( 'lets you switch storage type to sessionStorage' , async ( ) => {
303
303
vi . spyOn ( Object . getPrototypeOf ( window . sessionStorage ) , 'setItem' )
304
304
Object . setPrototypeOf ( window . sessionStorage . setItem , vi . fn ( ) )
305
305
@@ -313,4 +313,22 @@ describe('persisted()', () => {
313
313
314
314
expect ( window . sessionStorage . setItem ) . toHaveBeenCalled ( )
315
315
} )
316
- } )
316
+
317
+ it ( "lets you switch storage type to indexedDB" , async ( ) => {
318
+ /* Testing direct calls to the mock IndexedDB is not feasible due to the timing
319
+ of spy setup and localforage import.
320
+ Localforage's internal calls to IndexedDB occur before the spy can be set up.
321
+ As a workaround, verify if localforage's setDriver method was called with the correct arguments. */
322
+ const setDriverSpy = vi . spyOn ( localforage , "setDriver" ) ;
323
+
324
+ const value = "foo" ;
325
+
326
+ const store = await persisted ( "myKey12" , value , {
327
+ storage : "indexedDB" ,
328
+ } ) ;
329
+
330
+ await store . set ( "bar" ) ;
331
+
332
+ expect ( setDriverSpy ) . toHaveBeenCalledWith ( localforage . INDEXEDDB ) ;
333
+ } ) ;
334
+ } )
0 commit comments