Skip to content

Commit

Permalink
Guard against null children
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaleaps committed Mar 6, 2018
1 parent 77d37de commit 3b40652
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class MediaQuery extends React.Component {
const props = omit(this.props, excludedPropKeys)
const hasMergeProps = Object.keys(props).length > 0
const childrenCount = React.Children.count(this.props.children)
const wrapChildren = this.props.component || this.props.children === undefined
const wrapChildren = this.props.component || this.props.children == null
if (wrapChildren) {
return React.createElement(
this.props.component || 'div',
Expand Down
8 changes: 8 additions & 0 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ describe('MediaQuery', function () {
const e = TestUtils.renderIntoDocument(mq)
assert.isNotFalse(TestUtils.findRenderedDOMComponentWithClass(e, 'parentBox'))
})
it('doesnt throw error when component with null children', function () {
const mq = (
<MediaQuery all className="parentBox">{null}</MediaQuery>
)
const e = TestUtils.renderIntoDocument(mq)
assert.isNotFalse(TestUtils.findRenderedDOMComponentWithClass(e, 'parentBox'))
})

it('renders with output of callback', function () {
const mq = (
<MediaQuery maxWidth={300}>
Expand Down

0 comments on commit 3b40652

Please sign in to comment.