Skip to content

Commit a0724f1

Browse files
committed
Add RouteStore spec
1 parent a253b08 commit a0724f1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

modules/stores/RouteStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var RouteStore = {
8080
* Returns the Route object with the given name, if one exists.
8181
*/
8282
getRouteByName: function (routeName) {
83-
return _namedRoutes[routeName];
83+
return _namedRoutes[routeName] || null;
8484
}
8585

8686
};

specs/RouteStore.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require('./helper');
2+
var RouteStore = require('../modules/stores/RouteStore');
3+
var Route = require('../modules/components/Route');
4+
5+
var App = React.createClass({
6+
displayName: 'App',
7+
render: function () {
8+
return React.DOM.div();
9+
}
10+
});
11+
12+
describe('when a route with a given name is not present', function () {
13+
it('returns null', function () {
14+
expect(RouteStore.getRouteByName('products')).toBe(null);
15+
});
16+
});
17+
18+
describe('when a route is looked up by name', function () {
19+
var route;
20+
beforeEach(function () {
21+
route = Route({ name: 'products', handler: App });
22+
RouteStore.registerRoute(route);
23+
});
24+
25+
afterEach(function () {
26+
RouteStore.unregisterRoute(route);
27+
});
28+
29+
it('returns that route', function () {
30+
expect(RouteStore.getRouteByName('products')).toEqual(route);
31+
});
32+
});

0 commit comments

Comments
 (0)