Skip to content

Commit b8c1820

Browse files
committed
Update and consolidate tests
1 parent 400734e commit b8c1820

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

modules/__tests__/matchRoutes-test.js

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,16 @@ describe('matchRoutes', function () {
291291
})
292292

293293
describe('an asynchronous JSX route config', function () {
294-
let getChildRoutes, getIndexRoute, jsxRoutes
294+
let getChildRoutes, getIndexRoute, jsxRoutes, jsxNestedRoutes, state
295295

296296
beforeEach(function () {
297297
getChildRoutes = function (partialNextState, callback) {
298+
state = partialNextState
298299
setTimeout(function () {
299300
callback(null, <Route path=":userID" />)
300301
})
301302
}
302-
303+
303304
getIndexRoute = function (location, callback) {
304305
setTimeout(function () {
305306
callback(null, <Route name="jsx" />)
@@ -310,9 +311,18 @@ describe('matchRoutes', function () {
310311
<Route name="users"
311312
path="users"
312313
getChildRoutes={getChildRoutes}
313-
getIndexRoute={getIndexRoute} />
314+
getIndexRoute={getIndexRoute} />
314315
])
315-
})
316+
317+
jsxNestedRoutes = createRoutes([
318+
<Route name="users"
319+
path="users/:id">
320+
<Route name="topic"
321+
path=":topic"
322+
getChildRoutes={getChildRoutes} />
323+
</Route>
324+
])
325+
})
316326

317327
it('when getChildRoutes callback returns reactElements', function (done) {
318328
matchRoutes(jsxRoutes, createLocation('/users/5'), function (error, match) {
@@ -330,32 +340,11 @@ describe('matchRoutes', function () {
330340
done()
331341
})
332342
})
333-
})
334-
335-
describe('a nested route with a getChildRoutes callback', function () {
336-
let getChildRoutes, jsxRoutes
337-
338-
beforeEach(function () {
339-
getChildRoutes = function (partialNextState, callback) {
340-
setTimeout(function () {
341-
callback(null, partialNextState)
342-
})
343-
}
344-
345-
jsxRoutes = createRoutes([
346-
<Route name="users"
347-
path="users/:id">
348-
<Route name="topic"
349-
path=":topic"
350-
getChildRoutes={getChildRoutes} />
351-
</Route>
352-
])
353-
})
354-
343+
355344
it('when getChildRoutes callback returns partialNextState', function (done) {
356-
matchRoutes(jsxRoutes, createLocation('/users/5/details'), function (error, partialNextState) {
357-
expect(partialNextState).toExist()
358-
expect(partialNextState.params).toEqual({ id: '5', topic: 'details' })
345+
matchRoutes(jsxNestedRoutes, createLocation('/users/5/details/others'), function () {
346+
expect(state).toExist()
347+
expect(state.params).toEqual({ id: '5', topic: 'details' })
359348
done()
360349
})
361350
})

0 commit comments

Comments
 (0)