Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c4336dd

Browse files
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(/sureyouarepassingtheproperthemedescriptors/)
563+
})
558564
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /