Skip to content

Commit

Permalink
fix(classname): support mix via valueOf method
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Stenin authored and yarastqt committed Feb 11, 2021
1 parent 9097e28 commit 243575c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/classname/classname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export function withNaming(preset: Preset): ClassNameInitilizer {
const value = mix[i]

// Skipping non-string values and empty strings
if (typeof value !== 'string' || !value) continue
if (!value || typeof value.valueOf() !== 'string') continue

const mixes = value.split(' ')
const mixes = value.valueOf().split(' ')

for (let j = 0; j < mixes.length; j++) {
const val = mixes[j]
Expand Down
5 changes: 5 additions & 0 deletions packages/classname/test/classname.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ describe('@bem-react/classname', () => {
'Block-Elem Block-Elem_theme_normal Block-Elem_size_m',
)
})

test('object with valueOf', () => {
const b = cn('Block')
expect(b('Elem', null, [{ valueOf: () => 'Mix' } as string])).toEqual('Block-Elem Mix')
})
})
})

Expand Down

0 comments on commit 243575c

Please sign in to comment.