Skip to content

Commit

Permalink
fix(#255): handle falsy children values (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
doctyper committed Mar 24, 2017
1 parent 9afa44b commit 4a60765
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Helmet.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ const Helmet = (Component) => class HelmetWrapper extends React.Component {
let arrayTypeChildren = {};

React.Children.forEach(children, (child) => {
if (!child || !child.props) {
return;
}

const {children: nestedChildren, ...childProps} = child.props;
const newChildProps = convertReactPropstoHtmlAttributes(childProps);

Expand Down
18 changes: 18 additions & 0 deletions test/HelmetDeclarativeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,24 @@ describe("Helmet - Declarative API", () => {
expect(renderInvalid).to.throw(Error, "Helmet expects a string as a child of <script>. Did you forget to wrap your children in braces? ( <script>{``}</script> ) Refer to our API for more information.");
});

it("handles undefined children", (done) => {
const charSet = undefined;

ReactDOM.render(
<Helmet>
{charSet && <meta charSet={charSet} />}
<title>Test Title</title>
</Helmet>,
container
);

requestIdleCallback(() => {
expect(document.title).to.equal("Test Title");

done();
});
});

it("recognizes valid tags regardless of attribute ordering", (done) => {
ReactDOM.render(
<Helmet>
Expand Down

0 comments on commit 4a60765

Please sign in to comment.