@@ -572,15 +572,35 @@ describe('Parse.Object testing', () => {
572
572
const obj = new TestObject ( ) ;
573
573
obj . set ( 'items' , [ { value : 'a' , count : 5 } , { value : 'b' , count : 1 } ] ) ;
574
574
await obj . save ( ) ;
575
-
576
575
obj . increment ( 'items.0.count' , 15 ) ;
577
576
obj . increment ( 'items.1.count' , 4 ) ;
578
577
await obj . save ( ) ;
579
-
578
+ expect ( obj . toJSON ( ) . items [ 0 ] . value ) . toBe ( 'a' ) ;
579
+ expect ( obj . toJSON ( ) . items [ 1 ] . value ) . toBe ( 'b' ) ;
580
+ expect ( obj . toJSON ( ) . items [ 0 ] . count ) . toBe ( 20 ) ;
581
+ expect ( obj . toJSON ( ) . items [ 1 ] . count ) . toBe ( 5 ) ;
580
582
const query = new Parse . Query ( TestObject ) ;
581
583
const result = await query . get ( obj . id ) ;
584
+ expect ( result . get ( 'items' ) [ 0 ] . value ) . toBe ( 'a' ) ;
585
+ expect ( result . get ( 'items' ) [ 1 ] . value ) . toBe ( 'b' ) ;
582
586
expect ( result . get ( 'items' ) [ 0 ] . count ) . toBe ( 20 ) ;
583
587
expect ( result . get ( 'items' ) [ 1 ] . count ) . toBe ( 5 ) ;
588
+ expect ( result . get ( 'items' ) ) . toEqual ( obj . get ( 'items' ) ) ;
589
+ } ) ;
590
+
591
+ it_only_db ( 'mongo' ) ( 'can increment array nested fields missing index' , async ( ) => {
592
+ const obj = new TestObject ( ) ;
593
+ obj . set ( 'items' , [ ] ) ;
594
+ await obj . save ( ) ;
595
+ obj . increment ( 'items.1.count' , 15 ) ;
596
+ await obj . save ( ) ;
597
+ expect ( obj . toJSON ( ) . items [ 0 ] ) . toBe ( null ) ;
598
+ expect ( obj . toJSON ( ) . items [ 1 ] . count ) . toBe ( 15 ) ;
599
+ const query = new Parse . Query ( TestObject ) ;
600
+ const result = await query . get ( obj . id ) ;
601
+ expect ( result . get ( 'items' ) [ 0 ] ) . toBe ( null ) ;
602
+ expect ( result . get ( 'items' ) [ 1 ] . count ) . toBe ( 15 ) ;
603
+ expect ( result . get ( 'items' ) ) . toEqual ( obj . get ( 'items' ) ) ;
584
604
} ) ;
585
605
586
606
it ( 'addUnique with object' , function ( done ) {
0 commit comments