From 24dd4360d7617cd913722d0248dd1c45c9d59ed0 Mon Sep 17 00:00:00 2001 From: Omar Alshaker Date: Sat, 2 Jun 2018 23:03:37 +0200 Subject: [PATCH] Add failing test case for issue #31 --- test/spec/duplexSpec.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/spec/duplexSpec.js b/test/spec/duplexSpec.js index 11f0a19d..e280fa4f 100644 --- a/test/spec/duplexSpec.js +++ b/test/spec/duplexSpec.js @@ -1426,8 +1426,33 @@ describe('duplex', function() { }, 20); }); }); - describe('compare', function() { + it('Replacing a root array with an object should be handled well', function() { + + const obj = {}; + var patches = jsonpatch.compare(['jack'], obj); + expect(patches).toEqual([ + { + op: 'replace', + path: '/', + value: obj + } + ]); + + }); + it('Replacing a deep array with an object should be handled well', function() { + + const obj = {}; + var patches = jsonpatch.compare({arr: ['jack']}, {arr: obj}); + expect(patches).toEqual([ + { + op: 'replace', + path: '/arr', + value: obj + } + ]); + + }); it('should return an add for a property that does not exist in the first obj', function() { var objA = { user: {