fix: remove superfluous spaces when normalizing class (#3083)
Co-authored-by: Jacek Karczmarczyk <jkarczm@gmail.com>
This commit is contained in:
parent
49bc2e4db5
commit
4b551420fc
17
packages/shared/__tests__/normalizeProp.spec.ts
Normal file
17
packages/shared/__tests__/normalizeProp.spec.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { normalizeClass } from '../src'
|
||||
|
||||
describe('normalizeClass', () => {
|
||||
test('handles string correctly', () => {
|
||||
expect(normalizeClass('foo')).toEqual('foo')
|
||||
})
|
||||
|
||||
test('handles array correctly', () => {
|
||||
expect(normalizeClass(['foo', undefined, true, false, 'bar'])).toEqual('foo bar')
|
||||
})
|
||||
|
||||
test('handles object correctly', () => {
|
||||
expect(normalizeClass({ foo: true, bar: false, baz: true })).toEqual(
|
||||
'foo baz'
|
||||
)
|
||||
})
|
||||
})
|
@ -62,7 +62,10 @@ export function normalizeClass(value: unknown): string {
|
||||
res = value
|
||||
} else if (isArray(value)) {
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
res += normalizeClass(value[i]) + ' '
|
||||
const normalized = normalizeClass(value[i])
|
||||
if (normalized) {
|
||||
res += normalized + ' '
|
||||
}
|
||||
}
|
||||
} else if (isObject(value)) {
|
||||
for (const name in value) {
|
||||
|
Loading…
Reference in New Issue
Block a user