Skip to content

Commit

Permalink
[fixed] Allow comments in JSX config
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jan 24, 2015
1 parent fa16383 commit df38294
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
14 changes: 0 additions & 14 deletions modules/__tests__/Router-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,20 +830,6 @@ describe('Router.run', function () {
});
});

it('does not break on falsy routes', function (done) {
var routes = [
<Route handler={Foo} path="/foo"/>,
null,
<Route handler={Bar} path="/bar"/>,
undefined
];
Router.run(routes, '/foo', function (Handler, state) {
var html = React.renderToString(<Handler/>);
expect(html).toMatch(/Foo/);
done();
});
});

it('matches nested routes', function (done) {
var routes = (
<Route handler={Nested} path='/'>
Expand Down
37 changes: 37 additions & 0 deletions modules/__tests__/createRoutesFromReactChildren-test.js
Original file line number Diff line number Diff line change
@@ -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 = [
<Route handler={Foo} path="/foo"/>,
null,
<Route handler={Bar} path="/bar"/>,
undefined
];

Router.run(routes, '/foo', function (Handler, state) {
var html = React.renderToString(<Handler/>);
expect(html).toMatch(/Foo/);
done();
});
});

it('works with comments', function (done) {
var routes = [
<Route handler={Nested} path="/foo">
// This is a comment.
<Route handler={Bar} path="/bar"/>
</Route>
];

Router.run(routes, '/bar', function (Handler, state) {
var html = React.renderToString(<Handler/>);
expect(html).toMatch(/Bar/);
done();
});
});
});
2 changes: 1 addition & 1 deletion modules/createRoutesFromReactChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function createRoutesFromReactChildren(children, parentRoute, namedRoutes) {

React.Children.forEach(children, function (child) {
// Exclude null values, <DefaultRoute>s and <NotFoundRoute>s.
if (child && (child = createRoute(child, parentRoute, namedRoutes)))
if (React.isValidElement(child) && (child = createRoute(child, parentRoute, namedRoutes)))
routes.push(child);
});

Expand Down

0 comments on commit df38294

Please sign in to comment.