From 2d25150a213ce63ba60f3be43f687f64d64005c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 28 Jul 2021 17:57:16 +0200 Subject: [PATCH] Write tests for recursivelyAssign() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- spec/unit/utils.spec.ts | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/spec/unit/utils.spec.ts b/spec/unit/utils.spec.ts index 9611511b4..12a83b235 100644 --- a/spec/unit/utils.spec.ts +++ b/spec/unit/utils.spec.ts @@ -493,4 +493,68 @@ describe("utils", function() { expect(deepSortedObjectEntries(input)).toMatchObject(output); }); }); + + describe("recursivelyAssign", () => { + it("doesn't override with null/undefined", () => { + const result = utils.recursivelyAssign( + { + string: "Hello world", + object: {}, + float: 0.1, + }, { + string: null, + object: undefined, + }, + true, + ); + + expect(result).toStrictEqual({ + string: "Hello world", + object: {}, + float: 0.1, + }); + }); + + it("assigns recursively", () => { + const result = utils.recursivelyAssign( + { + number: 42, + object: { + message: "Hello world", + day: "Monday", + langs: { + compiled: ["c++"], + }, + }, + thing: "string", + }, { + number: 2, + object: { + message: "How are you", + day: "Friday", + langs: { + compiled: ["c++", "c"], + }, + }, + thing: { + aSubThing: "something", + }, + }, + ); + + expect(result).toStrictEqual({ + number: 2, + object: { + message: "How are you", + day: "Friday", + langs: { + compiled: ["c++", "c"], + }, + }, + thing: { + aSubThing: "something", + }, + }); + }); + }); });