From c4336dd0cc185b692ebba896f0da9eb9067af27d Mon Sep 17 00:00:00 2001 From: Javi Velasco Date: Sat, 28 Jan 2017 12:08:02 +0100 Subject: [PATCH] Warn the case when a string is being merged with an object --- src/components/themr.js | 6 ++++++ test/components/themr.spec.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/components/themr.js b/src/components/themr.js index 01c6745..97a2328 100644 --- a/src/components/themr.js +++ b/src/components/themr.js @@ -183,6 +183,12 @@ export function themeable(original = {}, mixin) { let newValue + //when you are mixing an string with a object it should fail + invariant(!(typeof originalValue === 'string' && typeof mixinValue === 'object'), + `You are merging a string "${originalValue}" with an Object,` + + 'Make sure you are passing the proper theme descriptors.' + ) + //check if values are nested objects if (typeof originalValue === 'object' && typeof mixinValue === 'object') { //go recursive diff --git a/test/components/themr.spec.js b/test/components/themr.spec.js index 749158b..51b564b 100644 --- a/test/components/themr.spec.js +++ b/test/components/themr.spec.js @@ -555,4 +555,10 @@ describe('themeable function', () => { const result = themeable(themeA, themeB) expect(result).toEqual(expected) }) + + it('throws an exception when its called mixing a string with an object', () => { + expect(() => { + themeable('fail', { test: { foo: 'baz' } }) + }).toThrow(/sure you are passing the proper theme descriptors/) + }) })