File tree Expand file tree Collapse file tree 2 files changed +27
-12
lines changed Expand file tree Collapse file tree 2 files changed +27
-12
lines changed Original file line number Diff line number Diff line change @@ -677,19 +677,34 @@ describe('a generate json patch function', () => {
677
677
} ,
678
678
} ;
679
679
680
- const patch = generateJSONPatch ( before , after , { maxDepth : 3 } ) ;
681
- expect ( patch ) . to . eql ( [
682
- {
683
- op : 'replace' ,
684
- path : '/firstLevel/secondLevel' ,
685
- value : {
686
- thirdLevel : {
680
+ it ( 'detects changes as a given depth of 3' , ( ) => {
681
+ const patch = generateJSONPatch ( before , after , { maxDepth : 3 } ) ;
682
+ expect ( patch ) . to . eql ( [
683
+ {
684
+ op : 'replace' ,
685
+ path : '/firstLevel/secondLevel' ,
686
+ value : {
687
+ thirdLevel : {
688
+ fourthLevel : 'hello-brave-new-world' ,
689
+ } ,
690
+ thirdLevelTwo : 'hello' ,
691
+ } ,
692
+ } ,
693
+ ] ) ;
694
+ } ) ;
695
+
696
+ it ( 'detects changes as a given depth of 4' , ( ) => {
697
+ const patch = generateJSONPatch ( before , after , { maxDepth : 4 } ) ;
698
+ expect ( patch ) . to . eql ( [
699
+ {
700
+ op : 'replace' ,
701
+ path : '/firstLevel/secondLevel/thirdLevel' ,
702
+ value : {
687
703
fourthLevel : 'hello-brave-new-world' ,
688
704
} ,
689
- thirdLevelTwo : 'hello' ,
690
705
} ,
691
- } ,
692
- ] ) ;
706
+ ] ) ;
707
+ } ) ;
693
708
} ) ;
694
709
} ) ;
695
710
Original file line number Diff line number Diff line change @@ -186,8 +186,8 @@ export function generateJSONPatch(
186
186
compareArrays ( leftValue , rightValue , newPath ) ;
187
187
} else if ( isJsonObject ( rightValue ) ) {
188
188
if ( isJsonObject ( leftValue ) ) {
189
- if ( maxDepth <= path . split ( '/' ) . length ) {
190
- patch . push ( { op : 'replace' , path : path , value : rightJsonValue } ) ;
189
+ if ( maxDepth <= newPath . split ( '/' ) . length ) {
190
+ patch . push ( { op : 'replace' , path : newPath , value : rightValue } ) ;
191
191
} else {
192
192
compareObjects ( newPath , leftValue , rightValue ) ;
193
193
}
You can’t perform that action at this time.
0 commit comments