Skip to content

Commit

Permalink
fix: ✅ adding extra joinStyles() test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Sullivan committed Oct 23, 2022
1 parent a133232 commit a30388f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/styles.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export function joinStyles(...values: string[]) {
return values
.map(value => value.split(';').map(v => v.trim()))
.flat()
.filter(Boolean)
.join(';')
|| undefined
return (
values
.map(value => value.split(';').map(v => v.trim()))
.flat()
.filter(Boolean)
.join(';') || undefined
)
}
29 changes: 23 additions & 6 deletions tests/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@ import * as assert from 'uvu/assert'
import { joinStyles } from '../src/styles.js'

test('joinStyles', () => {
assert.type(joinStyles, 'function', 'joinStyles is a function')
assert.is(joinStyles(), undefined, 'undefined when no styles provided')
assert.is(joinStyles('color: red'), 'color: red', 'single style unchanged')
assert.is(joinStyles('color: red', 'background: blue'), 'color: red;background: blue', 'joins two styles')
assert.is(joinStyles('color: red;background: blue;', 'font-size: 16px'), 'color: red;background: blue;font-size: 16px', 'handles compound styles')
})
assert.type(joinStyles, 'function', 'joinStyles is a function')
assert.is(joinStyles(), undefined, 'undefined when no styles provided')
assert.is(joinStyles('color: red'), 'color: red', 'single style unchanged')
assert.is(
joinStyles('color: red', 'background: blue'),
'color: red;background: blue',
'joins two styles'
)
assert.is(
joinStyles('color: red;background: blue;', 'font-size: 16px'),
'color: red;background: blue;font-size: 16px',
'handles compound styles'
)
assert.is(
joinStyles(
'color: red; background: blue',
'font-size: 16px;',
'line-height: 1.5; font-weight: bold'
),
'color: red;background: blue;font-size: 16px;line-height: 1.5;font-weight: bold',
'three complex styles'
)
})

0 comments on commit a30388f

Please sign in to comment.