22import { getSnapshot } from 'mobx-state-tree'
33
44import { persist } from '../src/index'
5- import { UserStore } from './fixtures'
5+ import { UserStore , persistedData } from './fixtures'
66
77function getItem ( key : string ) {
88 const item = window . localStorage . getItem ( key )
99 return item ? JSON . parse ( item ) : null // can only parse strings
1010}
1111
12- describe ( 'basic persist options ' , ( ) => {
12+ describe ( 'persist' , ( ) => {
1313 beforeEach ( ( ) => window . localStorage . clear ( ) )
1414
1515 it ( 'should persist nothing if no actions are used' , async ( ) => {
@@ -27,6 +27,14 @@ describe('basic persist options', () => {
2727 expect ( getItem ( 'user' ) ) . toStrictEqual ( getSnapshot ( user ) )
2828 } )
2929
30+ it ( 'should load persisted data' , async ( ) => {
31+ window . localStorage . setItem ( 'user' , JSON . stringify ( persistedData ) )
32+
33+ const user = UserStore . create ( )
34+ await persist ( 'user' , user )
35+ expect ( getSnapshot ( user ) ) . toStrictEqual ( persistedData )
36+ } )
37+
3038 it ( 'shouldn\'t jsonify' , async ( ) => {
3139 const user = UserStore . create ( )
3240 await persist ( 'user' , user , {
0 commit comments