fix: remove superfluous spaces when normalizing class (#3083)

Co-authored-by: Jacek Karczmarczyk <jkarczm@gmail.com>
This commit is contained in:
Albert Kaaman 2021-02-04 14:41:46 +01:00 committed by GitHub
parent 49bc2e4db5
commit 4b551420fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View 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'
)
})
})

View File

@ -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) {