From 278c2031fb4529c577c74b18938a0ae38d32226e Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Fri, 13 Nov 2020 19:51:05 -0500 Subject: [PATCH] Fix bug where color palette could not be empty --- __tests__/flattenColorPalette.test.js | 4 ++++ src/util/flattenColorPalette.js | 1 + 2 files changed, 5 insertions(+) diff --git a/__tests__/flattenColorPalette.test.js b/__tests__/flattenColorPalette.test.js index 384c2f672122..e8edcd9aa18a 100644 --- a/__tests__/flattenColorPalette.test.js +++ b/__tests__/flattenColorPalette.test.js @@ -75,3 +75,7 @@ test('it flattens deeply nested color objects', () => { 'button-primary-focus-variant': 'orange', }) }) + +test('it handles empty objects', () => { + expect(flattenColorPalette({})).toEqual({}) +}) diff --git a/src/util/flattenColorPalette.js b/src/util/flattenColorPalette.js index de094a3cb0c7..79b8dc3e83b7 100644 --- a/src/util/flattenColorPalette.js +++ b/src/util/flattenColorPalette.js @@ -1,5 +1,6 @@ const flattenColorPalette = (colors) => Object.assign( + {}, ...Object.entries(colors).flatMap(([color, values]) => typeof values == 'object' ? Object.entries(flattenColorPalette(values)).map(([number, hex]) => ({