From df382947594a1cc10483303843f4acce369610ba Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Sat, 24 Jan 2015 12:21:01 -0800 Subject: [PATCH] [fixed] Allow comments in JSX config Fixes #672 --- modules/__tests__/Router-test.js | 14 ------- .../createRoutesFromReactChildren-test.js | 37 +++++++++++++++++++ modules/createRoutesFromReactChildren.js | 2 +- 3 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 modules/__tests__/createRoutesFromReactChildren-test.js diff --git a/modules/__tests__/Router-test.js b/modules/__tests__/Router-test.js index 8cf8a23809..f5accab3b6 100644 --- a/modules/__tests__/Router-test.js +++ b/modules/__tests__/Router-test.js @@ -830,20 +830,6 @@ describe('Router.run', function () { }); }); - it('does not break on falsy routes', function (done) { - var routes = [ - , - null, - , - undefined - ]; - Router.run(routes, '/foo', function (Handler, state) { - var html = React.renderToString(); - expect(html).toMatch(/Foo/); - done(); - }); - }); - it('matches nested routes', function (done) { var routes = ( diff --git a/modules/__tests__/createRoutesFromReactChildren-test.js b/modules/__tests__/createRoutesFromReactChildren-test.js new file mode 100644 index 0000000000..b3760b3a6f --- /dev/null +++ b/modules/__tests__/createRoutesFromReactChildren-test.js @@ -0,0 +1,37 @@ +var expect = require('expect'); +var React = require('react'); +var Router = require('../index'); +var Route = require('../components/Route'); +var { Foo, Bar, Nested } = require('../utils/TestHandlers'); + +describe('creating routes from ReactChildren', function () { + it('works with falsy children', function (done) { + var routes = [ + , + null, + , + undefined + ]; + + Router.run(routes, '/foo', function (Handler, state) { + var html = React.renderToString(); + expect(html).toMatch(/Foo/); + done(); + }); + }); + + it('works with comments', function (done) { + var routes = [ + + // This is a comment. + + + ]; + + Router.run(routes, '/bar', function (Handler, state) { + var html = React.renderToString(); + expect(html).toMatch(/Bar/); + done(); + }); + }); +}); diff --git a/modules/createRoutesFromReactChildren.js b/modules/createRoutesFromReactChildren.js index 51217894a1..b91387c86e 100644 --- a/modules/createRoutesFromReactChildren.js +++ b/modules/createRoutesFromReactChildren.js @@ -149,7 +149,7 @@ function createRoutesFromReactChildren(children, parentRoute, namedRoutes) { React.Children.forEach(children, function (child) { // Exclude null values, s and s. - if (child && (child = createRoute(child, parentRoute, namedRoutes))) + if (React.isValidElement(child) && (child = createRoute(child, parentRoute, namedRoutes))) routes.push(child); });