Skip to content

Commit

Permalink
Handle boolean values (#360)
Browse files Browse the repository at this point in the history
* Handle false literals in interpolations.

* Add another test for explicit false

* Check for true

* Remove typeof value === 'boolean' since value does not exist
  • Loading branch information
Kye Hohenberger authored and emmatown committed Sep 30, 2017
1 parent 5e82256 commit 8234cbd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/emotion/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function handleInterpolation(
if (
interpolation === undefined ||
interpolation === null ||
typeof value === 'boolean'
typeof interpolation === 'boolean'
) {
return ''
}
Expand Down
32 changes: 32 additions & 0 deletions packages/emotion/test/__snapshots__/css.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ exports[`css @supports 1`] = `
/>
`;

exports[`css array with explicit false 1`] = `
.glamor-0 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
<div
className="glamor-0"
/>
`;

exports[`css array with explicit true 1`] = `
.glamor-0 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
<div
className="glamor-0"
/>
`;

exports[`css auto px 1`] = `
.glamor-0 {
display: -webkit-box;
Expand Down Expand Up @@ -160,6 +186,12 @@ exports[`css explicit & 2`] = `
}"
`;

exports[`css explicit false 1`] = `
<div
className="css-0"
/>
`;

exports[`css falsy property value in object 1`] = `
.glamor-0 {
display: -webkit-box;
Expand Down
19 changes: 19 additions & 0 deletions packages/emotion/test/css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,25 @@ describe('css', () => {
const tree = renderer.create(<div className={cls1} />).toJSON()
expect(tree).toMatchSnapshot()
})

test('explicit false', () => {
const cls1 = css(false)
const tree = renderer.create(<div className={cls1} />).toJSON()
expect(tree).toMatchSnapshot()
})

test('array with explicit false', () => {
const cls1 = css([[{ display: 'flex' }], false])
const tree = renderer.create(<div className={cls1} />).toJSON()
expect(tree).toMatchSnapshot()
})

test('array with explicit true', () => {
const cls1 = css([[{ display: 'flex' }], true])
const tree = renderer.create(<div className={cls1} />).toJSON()
expect(tree).toMatchSnapshot()
})

test('nested', () => {
const cls1 = css`
color: yellow;
Expand Down

0 comments on commit 8234cbd

Please sign in to comment.