Skip to content

Commit

Permalink
fix: remove superfluous spaces when normalizing class (#3083)
Browse files Browse the repository at this point in the history
Co-authored-by: Jacek Karczmarczyk <jkarczm@gmail.com>
  • Loading branch information
nekosaur and jacekkarczmarczyk committed Feb 4, 2021
1 parent 49bc2e4 commit 4b55142
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/shared/__tests__/normalizeProp.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
)
})
})
5 changes: 4 additions & 1 deletion packages/shared/src/normalizeProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4b55142

Please sign in to comment.