Skip to content

Commit

Permalink
Warn the case when a string is being merged with an object
Browse files Browse the repository at this point in the history
  • Loading branch information
javivelasco committed Jan 28, 2017
1 parent cb0501f commit c4336dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/themr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/components/themr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
})
})

0 comments on commit c4336dd

Please sign in to comment.