Skip to content

Commit

Permalink
add null check when building up class list (fixes FortAwesome#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimericdream committed Oct 3, 2019
1 parent 50a087f commit 948ea31
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
39 changes: 39 additions & 0 deletions src/utils/__tests__/get-class-list-from-props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,43 @@ describe('get class list', () => {
testPull('left')
testPull('right')
})

describe('when some props are null', () => {
function testNulls(prop) {
const NUM_CLASSES = 6

const props = {
spin: true,
pulse: true,
fixedWidth: true,
inverse: true,
border: true,
listItem: true,
[prop]: null
}

const classList = getClassList(props)
expect(classList.length).toBe(NUM_CLASSES)
expect(classList).toStrictEqual([
'fa-spin',
'fa-pulse',
'fa-fw',
'fa-inverse',
'fa-border',
'fa-li'
])
}

test('pull', () => {
testNulls('pull')
})

test('rotation', () => {
testNulls('rotation')
})

test('size', () => {
testNulls('size')
})
})
})
7 changes: 4 additions & 3 deletions src/utils/get-class-list-from-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export default function classList(props) {
'fa-li': listItem,
'fa-flip-horizontal': flip === 'horizontal' || flip === 'both',
'fa-flip-vertical': flip === 'vertical' || flip === 'both',
[`fa-${size}`]: typeof size !== 'undefined',
[`fa-rotate-${rotation}`]: typeof rotation !== 'undefined',
[`fa-pull-${pull}`]: typeof pull !== 'undefined',
[`fa-${size}`]: typeof size !== 'undefined' && size !== null,
[`fa-rotate-${rotation}`]:
typeof rotation !== 'undefined' && rotation !== null,
[`fa-pull-${pull}`]: typeof pull !== 'undefined' && pull !== null,
'fa-swap-opacity': props.swapOpacity
}

Expand Down

0 comments on commit 948ea31

Please sign in to comment.