forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[added] ability to set params/query in Redirect
closes remix-run#275 closes remix-run#294
- Loading branch information
1 parent
acc00f7
commit 6723dc5
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
var assert = require('assert'); | ||
var expect = require('expect'); | ||
var React = require('react/addons'); | ||
var Route = require('../Route'); | ||
var Redirect = require('../Redirect'); | ||
var Routes = require('../Routes'); | ||
|
||
describe('a Redirect', function () { | ||
|
||
it('redirects from old to new', function (done) { | ||
var descriptor = Redirect({ from: 'old', to: 'new' }); | ||
|
||
expect(descriptor.props.path).toEqual('old'); | ||
|
||
var fakeTransition = { | ||
redirect: function(to) { | ||
expect(to).toEqual('new'); | ||
done(); | ||
} | ||
}; | ||
|
||
descriptor.props.handler.willTransitionTo(fakeTransition); | ||
}); | ||
|
||
it('uses params and query from current path', function (done) { | ||
var descriptor = Redirect({ from: 'old', to: 'new' }); | ||
var expectedParams = { foo: 'bar' }; | ||
var expectedQuery = { baz: 'qux' }; | ||
|
||
var fakeTransition = { | ||
redirect: function(to, params, query) { | ||
expect(params).toEqual(expectedParams); | ||
expect(query).toEqual(expectedQuery); | ||
done(); | ||
} | ||
}; | ||
|
||
descriptor.props.handler.willTransitionTo(fakeTransition, expectedParams, expectedQuery); | ||
}); | ||
|
||
it('uses params and query from the Redirect definition', function (done) { | ||
var expectedParams = { foo: 'bar' }; | ||
var expectedQuery = { baz: 'qux' }; | ||
var fakePathParams = { hooba: 'scooba' }; | ||
var fakePathQuery = { doobie: 'scoobie' }; | ||
|
||
var descriptor = Redirect({ | ||
from: 'old', | ||
to: 'new', | ||
params: expectedParams, | ||
query: expectedQuery | ||
}); | ||
|
||
var fakeTransition = { | ||
redirect: function(to, params, query) { | ||
expect(params).toEqual(expectedParams); | ||
expect(query).toEqual(expectedQuery); | ||
done(); | ||
} | ||
}; | ||
|
||
descriptor.props.handler.willTransitionTo(fakeTransition, fakePathParams, fakePathQuery); | ||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters