Skip to content

Commit

Permalink
[fixed] Avoid some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jul 21, 2014
1 parent 31e0597 commit baf79b6
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions specs/Route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,31 @@ var App = React.createClass({

describe('a Route that matches the URL', function () {
it('returns an array', function () {
var route = Route({ path: '/a/b/c', handler: App });
var route = TestUtils.renderIntoDocument(
Route({ handler: App },
Route({ path: '/a/b/c', handler: App })
)
);

var matches = route.match('/a/b/c');
assert(matches);
expect(matches.length).toEqual(1);
expect(matches.length).toEqual(2);

var rootMatch = getRootMatch(matches);
expect(rootMatch.params).toEqual({});
});

describe('that contains dynamic segments', function () {
it('returns an array with the correct params', function () {
var route = Route({ path: '/posts/:id/edit', handler: App });
var route = TestUtils.renderIntoDocument(
Route({ handler: App },
Route({ path: '/posts/:id/edit', handler: App })
)
);

var matches = route.match('/posts/abc/edit');
assert(matches);
expect(matches.length).toEqual(1);
expect(matches.length).toEqual(2);

var rootMatch = getRootMatch(matches);
expect(rootMatch.params).toEqual({ id: 'abc' });
Expand All @@ -36,38 +44,49 @@ describe('a Route that matches the URL', function () {

describe('a Route that does not match the URL', function () {
it('returns null', function () {
var route = Route({ path: '/a/b/c', handler: App });
var route = TestUtils.renderIntoDocument(
Route({ handler: App },
Route({ path: '/a/b/c', handler: App })
)
);

expect(route.match('/not-found')).toBe(null);
});
});

describe('a nested Route that matches the URL', function () {
it('returns the appropriate params for each match', function () {
var route = Route({ name: 'posts', path: '/posts/:id', handler: App },
Route({ name: 'comment', path: '/posts/:id/comments/:commentId', handler: App })
var route = TestUtils.renderIntoDocument(
Route({ handler: App },
Route({ name: 'posts', path: '/posts/:id', handler: App },
Route({ name: 'comment', path: '/posts/:id/comments/:commentId', handler: App })
)
)
);

var matches = route.match('/posts/abc/comments/123');
assert(matches);
expect(matches.length).toEqual(2);
expect(matches.length).toEqual(3);

var rootMatch = getRootMatch(matches);
expect(rootMatch.route.props.name).toEqual('comment');
expect(rootMatch.params).toEqual({ id: 'abc', commentId: '123' });

var firstMatch = matches[0];
expect(firstMatch.route.props.name).toEqual('posts');
expect(firstMatch.params).toEqual({ id: 'abc' });
var postsMatch = matches[1];
expect(postsMatch.route.props.name).toEqual('posts');
expect(postsMatch.params).toEqual({ id: 'abc' });
});
});

describe('multiple nested Router that match the URL', function () {
it('returns the first one in the subtree, depth-first', function () {
var route = Route({ path: '/', handler: App },
Route({ path: '/a', handler: App },
Route({ path: '/a/b', name: 'expected', handler: App })
),
Route({ path: '/a/b', handler: App })
var route = TestUtils.renderIntoDocument(
Route({ handler: App },
Route({ path: '/a', handler: App },
Route({ path: '/a/b', name: 'expected', handler: App })
),
Route({ path: '/a/b', handler: App })
)
);

var matches = route.match('/a/b');
Expand All @@ -81,12 +100,13 @@ describe('multiple nested Router that match the URL', function () {

describe('a Route with custom props', function() {
it('receives props', function (done) {
var route = Route({ handler: App, customProp: 'prop' });
var component = TestUtils.renderIntoDocument(route);
var route = TestUtils.renderIntoDocument(
Route({ handler: App, customProp: 'prop' })
);

route.dispatch('/').then(function () {
assert(component.props.customProp);
expect(component.props.customProp).toEqual('prop');
assert(route.props.customProp);
expect(route.props.customProp).toEqual('prop');
done();
});
});
Expand Down

0 comments on commit baf79b6

Please sign in to comment.