@@ -76,7 +76,7 @@ it("respects nested values when it replaces store's state on initializing", () =
76
76
expect ( store . subscribe ) . toBeCalled ( ) ;
77
77
} ) ;
78
78
79
- test ( ' persist the changed parial state back to serialized JSON', ( ) => {
79
+ it ( 'should persist the changed parial state back to serialized JSON', ( ) => {
80
80
const storage = new Storage ( ) ;
81
81
const store = new Vuex . Store ( { state : { } } ) ;
82
82
@@ -133,7 +133,7 @@ it('persist the changed partial state back to serialized JSON under a nested pat
133
133
) ;
134
134
} ) ;
135
135
136
- it ( 'not persist null values' , ( ) => {
136
+ it ( 'should not persist null values' , ( ) => {
137
137
const storage = new Storage ( ) ;
138
138
const store = new Vuex . Store ( {
139
139
state : { alpha : { name : null , bravo : { name : null } } }
@@ -153,7 +153,7 @@ it('not persist null values', () => {
153
153
) ;
154
154
} ) ;
155
155
156
- it ( 'persist array values' , ( ) => {
156
+ it ( 'should not merge array values when rehydrating ' , ( ) => {
157
157
const storage = new Storage ( ) ;
158
158
storage . setItem ( 'vuex' , JSON . stringify ( { persisted : [ 'json' ] } ) ) ;
159
159
@@ -167,6 +167,29 @@ it('persist array values', () => {
167
167
expect ( store . replaceState ) . toBeCalledWith ( {
168
168
persisted : [ 'json' ] ,
169
169
} ) ;
170
+
171
+ expect ( store . subscribe ) . toBeCalled ( ) ;
172
+ } ) ;
173
+
174
+ it ( 'should not clone circular objects when rehydrating' , ( ) => {
175
+ const circular = { foo : 'bar' } ;
176
+ circular . foo = circular ;
177
+
178
+ const storage = new Storage ( ) ;
179
+ storage . setItem ( 'vuex' , JSON . stringify ( { persisted : 'baz' } ) ) ;
180
+
181
+ const store = new Vuex . Store ( { state : { circular } } ) ;
182
+ store . replaceState = jest . fn ( ) ;
183
+ store . subscribe = jest . fn ( ) ;
184
+
185
+ const plugin = createPersistedState ( { storage } ) ;
186
+ plugin ( store ) ;
187
+
188
+ expect ( store . replaceState ) . toBeCalledWith ( {
189
+ circular,
190
+ persisted : 'baz' ,
191
+ } ) ;
192
+
170
193
expect ( store . subscribe ) . toBeCalled ( ) ;
171
194
} ) ;
172
195
0 commit comments