@@ -224,6 +224,34 @@ describe('StatePersistent Tests', () => {
224224 }
225225 ) ;
226226
227+ it (
228+ "should load State value with Persistent key from the corresponding Storage, migrate it with the 'onMigrate()' method " +
229+ 'and apply it to the State if the loading was successful' ,
230+ async ( ) => {
231+ statePersistent . ready = true ;
232+ storageManager . get = jest . fn ( ( ) =>
233+ Promise . resolve ( 'dummyValue' as any )
234+ ) ;
235+ statePersistent . onMigrate = jest . fn ( ( value ) => `migrated_${ value } ` ) ;
236+
237+ const response = await statePersistent . loadPersistedValue ( ) ;
238+
239+ expect ( response ) . toBeTruthy ( ) ;
240+ expect ( storageManager . get ) . toHaveBeenCalledWith (
241+ statePersistent . _key ,
242+ statePersistent . config . defaultStorageKey
243+ ) ;
244+ expect ( dummyState . set ) . toHaveBeenCalledWith ( 'migrated_dummyValue' , {
245+ storage : false ,
246+ overwrite : true ,
247+ } ) ;
248+ expect ( statePersistent . onMigrate ) . toHaveBeenCalledWith ( 'dummyValue' ) ;
249+ expect ( statePersistent . setupSideEffects ) . toHaveBeenCalledWith (
250+ statePersistent . _key
251+ ) ;
252+ }
253+ ) ;
254+
227255 it (
228256 "shouldn't load State value with Persistent key from the corresponding Storage " +
229257 "and apply it to the State if the loading wasn't successful" ,
@@ -349,7 +377,9 @@ describe('StatePersistent Tests', () => {
349377 ( ) => {
350378 statePersistent . setupSideEffects ( ) ;
351379
352- expect ( dummyState . addSideEffect ) . toHaveBeenCalledWith (
380+ expect (
381+ dummyState . addSideEffect
382+ ) . toHaveBeenCalledWith (
353383 StatePersistent . storeValueSideEffectKey ,
354384 expect . any ( Function ) ,
355385 { weight : 0 }
@@ -502,6 +532,25 @@ describe('StatePersistent Tests', () => {
502532 ) ;
503533 } ) ;
504534
535+ it (
536+ 'should store current State value in the corresponding Storage ' +
537+ "and format it with the 'onSave()' method (default config)" ,
538+ ( ) => {
539+ statePersistent . onSave = jest . fn ( ( value ) => `save_${ value } ` ) ;
540+
541+ statePersistent . rebuildStorageSideEffect ( dummyState , 'coolKey' ) ;
542+
543+ expect ( storageManager . set ) . toHaveBeenCalledWith (
544+ 'coolKey' ,
545+ `save_${ dummyState . getPersistableValue ( ) } ` ,
546+ statePersistent . storageKeys
547+ ) ;
548+ expect ( statePersistent . onSave ) . toHaveBeenCalledWith (
549+ dummyState . getPersistableValue ( )
550+ ) ;
551+ }
552+ ) ;
553+
505554 it ( "shouldn't store State value in the corresponding Storage (config.storage = false)" , ( ) => {
506555 statePersistent . rebuildStorageSideEffect ( dummyState , 'coolKey' , {
507556 storage : false ,
0 commit comments