From bf828dea7f5b7e22f0eeeeba12769f04b9f9075e Mon Sep 17 00:00:00 2001 From: Oleg S <97077423+RobotSail@users.noreply.github.com> Date: Thu, 2 Mar 2023 09:07:09 -0500 Subject: [PATCH] test merging arrays and undefined objects Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com> --- packages/types/src/json.test.ts | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/types/src/json.test.ts b/packages/types/src/json.test.ts index 277992f00f..1210d0a773 100644 --- a/packages/types/src/json.test.ts +++ b/packages/types/src/json.test.ts @@ -170,4 +170,39 @@ describe('jsonMerge', () => { }, }); }); + + it("should overwrite the array with the second argument's array", () => { + const obj1 = { + array: ['a', 'b', 'c'], + }; + const obj2 = { + array: [1, 2, 3], + }; + const merged = mergeJson(obj1, obj2); + expect(merged).toEqual({ + array: [1, 2, 3], + }); + + const merged2 = mergeJson(obj2, obj1); + expect(merged2).toEqual({ + array: ['a', 'b', 'c'], + }); + }); + + it('should take only the defined value in the case of a collision', () => { + const obj1 = { + sqlite: undefined, + }; + const obj2 = { + sqlite: 'sqlite3', + }; + const merged = mergeJson(obj1, obj2); + expect(merged).toEqual({ + sqlite: 'sqlite3', + }); + const merged2 = mergeJson(obj2, obj1); + expect(merged2).toEqual({ + sqlite: 'sqlite3', + }); + }); });