-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
400734e
commit b8c1820
Showing
1 changed file
with
18 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,15 +291,16 @@ describe('matchRoutes', function () { | |
}) | ||
|
||
describe('an asynchronous JSX route config', function () { | ||
let getChildRoutes, getIndexRoute, jsxRoutes | ||
let getChildRoutes, getIndexRoute, jsxRoutes, jsxNestedRoutes, state | ||
|
||
beforeEach(function () { | ||
getChildRoutes = function (partialNextState, callback) { | ||
state = partialNextState | ||
This comment has been minimized.
Sorry, something went wrong. |
||
setTimeout(function () { | ||
callback(null, <Route path=":userID" />) | ||
}) | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong. |
||
getIndexRoute = function (location, callback) { | ||
setTimeout(function () { | ||
callback(null, <Route name="jsx" />) | ||
|
@@ -310,9 +311,18 @@ describe('matchRoutes', function () { | |
<Route name="users" | ||
path="users" | ||
getChildRoutes={getChildRoutes} | ||
getIndexRoute={getIndexRoute} /> | ||
getIndexRoute={getIndexRoute} /> | ||
This comment has been minimized.
Sorry, something went wrong.
taion
Contributor
|
||
]) | ||
}) | ||
|
||
jsxNestedRoutes = createRoutes([ | ||
<Route name="users" | ||
path="users/:id"> | ||
<Route name="topic" | ||
path=":topic" | ||
getChildRoutes={getChildRoutes} /> | ||
</Route> | ||
]) | ||
}) | ||
|
||
it('when getChildRoutes callback returns reactElements', function (done) { | ||
matchRoutes(jsxRoutes, createLocation('/users/5'), function (error, match) { | ||
|
@@ -330,32 +340,11 @@ describe('matchRoutes', function () { | |
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('a nested route with a getChildRoutes callback', function () { | ||
let getChildRoutes, jsxRoutes | ||
|
||
beforeEach(function () { | ||
getChildRoutes = function (partialNextState, callback) { | ||
setTimeout(function () { | ||
callback(null, partialNextState) | ||
}) | ||
} | ||
|
||
jsxRoutes = createRoutes([ | ||
<Route name="users" | ||
path="users/:id"> | ||
<Route name="topic" | ||
path=":topic" | ||
getChildRoutes={getChildRoutes} /> | ||
</Route> | ||
]) | ||
}) | ||
|
||
|
||
it('when getChildRoutes callback returns partialNextState', function (done) { | ||
matchRoutes(jsxRoutes, createLocation('/users/5/details'), function (error, partialNextState) { | ||
expect(partialNextState).toExist() | ||
expect(partialNextState.params).toEqual({ id: '5', topic: 'details' }) | ||
matchRoutes(jsxNestedRoutes, createLocation('/users/5/details/others'), function () { | ||
expect(state).toExist() | ||
expect(state.params).toEqual({ id: '5', topic: 'details' }) | ||
done() | ||
}) | ||
}) | ||
|
The value of
state
persists between test invocations, which could lead to potential problems. Instead usecreateSpy
and assert onspy.calls[0].arguments[0]
.