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', () => {
677677 } ,
678678 } ;
679679
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 : {
687703 fourthLevel : 'hello-brave-new-world' ,
688704 } ,
689- thirdLevelTwo : 'hello' ,
690705 } ,
691- } ,
692- ] ) ;
706+ ] ) ;
707+ } ) ;
693708 } ) ;
694709} ) ;
695710
Original file line number Diff line number Diff line change @@ -186,8 +186,8 @@ export function generateJSONPatch(
186186 compareArrays ( leftValue , rightValue , newPath ) ;
187187 } else if ( isJsonObject ( rightValue ) ) {
188188 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 } ) ;
191191 } else {
192192 compareObjects ( newPath , leftValue , rightValue ) ;
193193 }
You can’t perform that action at this time.
0 commit comments