@@ -184,14 +184,15 @@ describe('Module: LocalForageModule', function() {
184
184
it ( 'setItem and getItem should work' , function ( done ) {
185
185
var interval = triggerDigests ( ) ;
186
186
var objectToStore = {
187
+ $$hashKey : 'object:1' ,
187
188
name : 'Scott Trinh'
188
189
} ;
189
190
190
191
spyOn ( $localForage . _localforage , 'setItem' ) . and . callThrough ( ) ;
191
192
192
193
$localForage . setItem ( 'myObject' , objectToStore ) . then ( function ( data ) {
193
194
expect ( data ) . toEqual ( { name : 'Scott Trinh' } ) ;
194
- expect ( $localForage . _localforage . setItem . calls . mostRecent ( ) . args [ 1 ] ) . toBe ( objectToStore ) ;
195
+ expect ( $localForage . _localforage . setItem . calls . mostRecent ( ) . args [ 1 ] ) . toEqual ( { name : 'Scott Trinh' } ) ;
195
196
196
197
$localForage . getItem ( 'myObject' ) . then ( function ( data ) {
197
198
stopDigests ( interval ) ;
@@ -202,6 +203,84 @@ describe('Module: LocalForageModule', function() {
202
203
} , done ) ;
203
204
} ) ;
204
205
206
+ it ( 'setItem should remove $$hashKey from nested arrays' , function ( ) {
207
+ var arrayToStore = [
208
+ {
209
+ collection : [
210
+ { $$hashKey : 'object:1' } ,
211
+ { $$hashKey : 'object:2' }
212
+ ] ,
213
+ deeperCollection : {
214
+ collection : [
215
+ { $$hashKey : 'object:3' } ,
216
+ { $$hashKey : 'object:4' }
217
+ ]
218
+ }
219
+ }
220
+ ] ;
221
+
222
+ $localForage . setItem ( 'myArray' , arrayToStore ) . then ( function ( data ) {
223
+ expect ( data ) . toEqual ( [
224
+ {
225
+ collection : [ { } , { } ] ,
226
+ deeperCollection : {
227
+ collection : [ { } , { } ]
228
+ }
229
+ }
230
+ ] ) ;
231
+ expect ( arrayToStore ) . toEqual ( [
232
+ {
233
+ collection : [
234
+ { $$hashKey : 'object:1' } ,
235
+ { $$hashKey : 'object:2' }
236
+ ] ,
237
+ deeperCollection : {
238
+ collection : [
239
+ { $$hashKey : 'object:3' } ,
240
+ { $$hashKey : 'object:4' }
241
+ ]
242
+ }
243
+ }
244
+ ] ) ;
245
+ } ) ;
246
+ } ) ;
247
+
248
+ it ( 'setItem works with arrays of non-objects, and strips the $$hashKey of any object' , function ( ) {
249
+ var arrayToStore = [
250
+ [ [ ] ] ,
251
+ [ { } , { $$hashKey : 'object:1' } ] ,
252
+ 'string' ,
253
+ true ,
254
+ false ,
255
+ null ,
256
+ undefined ,
257
+ { } ,
258
+ ] ;
259
+
260
+ $localForage . setItem ( 'myWeirdArray' , arrayToStore ) . then ( function ( data ) {
261
+ expect ( data ) . toEqual ( [
262
+ [ [ ] ] ,
263
+ [ { } , { } ] ,
264
+ 'string' ,
265
+ true ,
266
+ false ,
267
+ null ,
268
+ undefined ,
269
+ { } ,
270
+ ] ) ;
271
+ expect ( arrayToStore ) . toEqual ( [
272
+ [ [ ] ] ,
273
+ [ { } , { $$hashKey : 'object:1' } ] ,
274
+ 'string' ,
275
+ true ,
276
+ false ,
277
+ null ,
278
+ undefined ,
279
+ { } ,
280
+ ] ) ;
281
+ } ) ;
282
+ } ) ;
283
+
205
284
it ( 'setItem error should reject promise' , function ( done ) {
206
285
var interval = triggerDigests ( ) ;
207
286
@@ -482,7 +561,8 @@ describe('Module: LocalForageModule', function() {
482
561
var setWith = $localForage . _localforage . setItem . calls . argsFor ( 0 ) [ 1 ] ;
483
562
var setWithNoPromise = $localForage . _localforage . setItem . calls . argsFor ( 1 ) [ 1 ] ;
484
563
expect ( setWith ) . not . toBe ( objectToStore ) ;
485
- expect ( setWith . childObject ) . toBe ( objectToStore . childObject ) ;
564
+ expect ( setWith . childObject ) . not . toBe ( objectToStore . childObject ) ;
565
+ expect ( setWith . childObject ) . toEqual ( objectToStore . childObject ) ;
486
566
expect ( setWith ) . toEqual ( {
487
567
childObject : { }
488
568
} ) ;
@@ -491,7 +571,7 @@ describe('Module: LocalForageModule', function() {
491
571
childObject : { }
492
572
} ) ;
493
573
494
- expect ( setWithNoPromise ) . toBe ( objectNoPromise ) ;
574
+ expect ( setWithNoPromise ) . toEqual ( objectNoPromise ) ;
495
575
496
576
$localForage . getItem ( 'myObject' ) . then ( function ( data ) {
497
577
stopDigests ( interval ) ;
0 commit comments