Skip to content

Commit

Permalink
doesnt throw error with empty children
Browse files Browse the repository at this point in the history
  • Loading branch information
nkov committed Jul 10, 2016
1 parent ba1cb39 commit df33365
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ var mq = React.createClass({
var hasMergeProps = Object.keys(props).length > 0;
var wrapChildren = this.props.component ||
React.Children.count(this.props.children) > 1 ||
typeof this.props.children === 'string';
typeof this.props.children === 'string' ||
this.props.children === undefined;
if (wrapChildren) {
return React.createElement(
this.props.component || 'div',
Expand Down
9 changes: 8 additions & 1 deletion test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('MediaQuery', function() {
});
it('throws if theres a bad query', function() {
const mq = (
<MediaQuery>
<MediaQuery doesntExist='test'>
<div className="childComponent"></div>
</MediaQuery>
);
Expand All @@ -116,4 +116,11 @@ describe('MediaQuery', function() {
const e = TestUtils.renderIntoDocument(mq);
assert.throws(() => (TestUtils.findRenderedDOMComponentWithClass(e, 'childComponent')), /Did not find exactly one match/);
});
it('doesnt throw error when unspecificed component with empty children', function() {
const mq = (
<MediaQuery all className='parentBox' />
);
const e = TestUtils.renderIntoDocument(mq);
assert.isNotFalse(TestUtils.findRenderedDOMComponentWithClass(e, 'parentBox'));
})
});

0 comments on commit df33365

Please sign in to comment.