diff --git a/packages/shared/__tests__/normalizeProp.spec.ts b/packages/shared/__tests__/normalizeProp.spec.ts new file mode 100644 index 00000000..f55f7f7b --- /dev/null +++ b/packages/shared/__tests__/normalizeProp.spec.ts @@ -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' + ) + }) +}) diff --git a/packages/shared/src/normalizeProp.ts b/packages/shared/src/normalizeProp.ts index 5e0f8405..1ff825bd 100644 --- a/packages/shared/src/normalizeProp.ts +++ b/packages/shared/src/normalizeProp.ts @@ -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) {