Skip to content

Commit 94bf0d7

Browse files
committed
Merge pull request #7 from limscoder/master
Fixed errors when there are undefined or null children.
2 parents 060500c + 51bbbaa commit 94bf0d7

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/__tests__/index-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ describe('props', () => {
5959
});
6060
});
6161

62+
it('does not error if there are undefined children', () => {
63+
var undefChild;
64+
doNotExpectWarning(assertions.props.onClick.NO_LABEL.msg, () => {
65+
<div onClick={k}>{ undefChild } bar</div>;
66+
});
67+
});
68+
69+
it('does not error if there are null children', () => {
70+
doNotExpectWarning(assertions.props.onClick.NO_LABEL.msg, () => {
71+
<div onClick={k}>bar { null }</div>;
72+
});
73+
});
74+
6275
it('does not warn if there is an image with an alt attribute', () => {
6376
doNotExpectWarning(assertions.props.onClick.NO_LABEL.msg, () => {
6477
<div onClick={k}><img src="#" alt="Foo"/></div>;
@@ -169,4 +182,3 @@ describe('tags', () => {
169182
});
170183
});
171184
});
172-

lib/assertions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ var hasChildTextNode = (props, children) => {
2323
React.Children.forEach(children, (child) => {
2424
if (hasText)
2525
return;
26+
else if (child === null)
27+
return;
28+
else if (typeof child === 'undefined')
29+
return;
2630
else if (typeof child === 'string')
2731
hasText = true;
2832
else if (child.type === 'img' && child.props.alt)
@@ -108,4 +112,3 @@ exports.tags = {
108112
}
109113
}
110114
};
111-

0 commit comments

Comments
 (0)