From 30fe1209ede399313c5e43bab931cf19bb29abcd Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Fri, 20 Oct 2023 15:22:06 +0200 Subject: [PATCH 1/3] chore: add test --- apps/app/src/lib/__tests__/util.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 apps/app/src/lib/__tests__/util.test.ts diff --git a/apps/app/src/lib/__tests__/util.test.ts b/apps/app/src/lib/__tests__/util.test.ts new file mode 100644 index 00000000..2aff587c --- /dev/null +++ b/apps/app/src/lib/__tests__/util.test.ts @@ -0,0 +1,22 @@ +import { deepExtendRemovingUndefined } from '../util' + +test('deepExtendRemovingUndefined', () => { + { + const target = { + a: 1, + } + deepExtendRemovingUndefined(target, { + b: 2, + }) + expect(target).toStrictEqual({ a: 1, b: 2 }) + } + { + const target = { + a: [1, 2, 3], + } + deepExtendRemovingUndefined(target, { + a: [4, 5, 6], + }) + expect(target).toStrictEqual({ a: [4, 5, 6] }) + } +}) From e16c389acc8765be618616b0ab98c33a1667276d Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Fri, 20 Oct 2023 15:56:20 +0200 Subject: [PATCH 2/3] fix: don't merge arrays --- apps/app/src/lib/util.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/app/src/lib/util.ts b/apps/app/src/lib/util.ts index 743e684e..a94c5dce 100644 --- a/apps/app/src/lib/util.ts +++ b/apps/app/src/lib/util.ts @@ -871,4 +871,5 @@ export const deepExtendRemovingUndefined = deepmergeIntoCustom({ } } }, + mergeArrays: false, }) From dbc760e0e576ee638048625ebb4f1950b3773bbe Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Fri, 20 Oct 2023 15:56:30 +0200 Subject: [PATCH 3/3] chore: add test --- apps/app/src/lib/__tests__/util.test.ts | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/apps/app/src/lib/__tests__/util.test.ts b/apps/app/src/lib/__tests__/util.test.ts index 2aff587c..fc83112b 100644 --- a/apps/app/src/lib/__tests__/util.test.ts +++ b/apps/app/src/lib/__tests__/util.test.ts @@ -19,4 +19,69 @@ test('deepExtendRemovingUndefined', () => { }) expect(target).toStrictEqual({ a: [4, 5, 6] }) } + + { + const target = { + arr: [1, 2, 3], + obj: { + num: 1, + arr: [ + { + a: 1, + }, + { + b: 2, + }, + ], + obj: { + a: 1, + }, + toBeUndefined: { + a: 1, + }, + }, + } + deepExtendRemovingUndefined(target, { + arr: [3, 4, 5], + obj: { + num: 2, + arr: [ + { + a: 2, + }, + { + b: 3, + }, + { + c: 4, + }, + ], + obj: { + b: 2, + }, + toBeUndefined: undefined, + }, + }) + expect(target).toStrictEqual({ + arr: [3, 4, 5], + obj: { + num: 2, + arr: [ + { + a: 2, + }, + { + b: 3, + }, + { + c: 4, + }, + ], + obj: { + a: 1, + b: 2, + }, + }, + }) + } })