Skip to content

Commit c4336dd

Browse files
committed
Warn the case when a string is being merged with an object
1 parent cb0501f commit c4336dd

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/components/themr.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ export function themeable(original = {}, mixin) {
183183

184184
let newValue
185185

186+
//when you are mixing an string with a object it should fail
187+
invariant(!(typeof originalValue === 'string' && typeof mixinValue === 'object'),
188+
`You are merging a string "${originalValue}" with an Object,` +
189+
'Make sure you are passing the proper theme descriptors.'
190+
)
191+
186192
//check if values are nested objects
187193
if (typeof originalValue === 'object' && typeof mixinValue === 'object') {
188194
//go recursive

test/components/themr.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,10 @@ describe('themeable function', () => {
555555
const result = themeable(themeA, themeB)
556556
expect(result).toEqual(expected)
557557
})
558+
559+
it('throws an exception when its called mixing a string with an object', () => {
560+
expect(() => {
561+
themeable('fail', { test: { foo: 'baz' } })
562+
}).toThrow(/sure you are passing the proper theme descriptors/)
563+
})
558564
})

0 commit comments

Comments
 (0)