File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -824,6 +824,35 @@ describe('a generate json patch function', () => {
824824 expect ( patch ) . to . eql ( [ ] ) ;
825825 } ) ;
826826 } ) ;
827+
828+ describe ( 'with object prototypes' , ( ) => {
829+ it ( 'handles objects' , ( ) => {
830+ class MySubObject {
831+ c = '' ;
832+ d = 0 ;
833+ }
834+
835+ class MyObject {
836+ a = new MySubObject ( ) ;
837+ b = '' ;
838+
839+ method ( ) {
840+ return 'hello' ;
841+ }
842+ }
843+
844+ const before = new MyObject ( ) ;
845+ const after = new MyObject ( ) ;
846+ after . b = 'changed' ;
847+ after . a . d = 42 ;
848+
849+ const patch = generateJSONPatch ( before , after ) ;
850+ expect ( patch ) . to . eql ( [
851+ { op : 'replace' , path : '/a/d' , value : 42 } ,
852+ { op : 'replace' , path : '/b' , value : 'changed' } ,
853+ ] ) ;
854+ } ) ;
855+ } ) ;
827856} ) ;
828857
829858function doPatch ( json : JsonValue , patch : Patch ) {
Original file line number Diff line number Diff line change @@ -248,7 +248,7 @@ function isPrimitiveValue(value: JsonValue): value is JsonValue {
248248}
249249
250250function isJsonObject ( value : JsonValue ) : value is JsonObject {
251- return value ?. constructor === Object ;
251+ return value !== null && typeof value === 'object' && ! Array . isArray ( value ) ;
252252}
253253
254254function deepEqual ( objA : any , objB : any ) {
You can’t perform that action at this time.
0 commit comments