Skip to content

Commit

Permalink
Update and consolidate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avanderhoorn committed Jun 21, 2016
1 parent 400734e commit b8c1820
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions modules/__tests__/matchRoutes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
@taion

taion Jun 21, 2016

Contributor

The value of state persists between test invocations, which could lead to potential problems. Instead use createSpy and assert on spy.calls[0].arguments[0].

setTimeout(function () {
callback(null, <Route path=":userID" />)
})
}

This comment has been minimized.

Copy link
@taion

taion Jun 21, 2016

Contributor

trailing whitespace

getIndexRoute = function (location, callback) {
setTimeout(function () {
callback(null, <Route name="jsx" />)
Expand All @@ -310,9 +311,18 @@ describe('matchRoutes', function () {
<Route name="users"
path="users"
getChildRoutes={getChildRoutes}
getIndexRoute={getIndexRoute} />
getIndexRoute={getIndexRoute} />

This comment has been minimized.

Copy link
@taion

taion Jun 21, 2016

Contributor

trailing whitespace... I'm surprised our linting doesn't pick this up

])
})

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) {
Expand All @@ -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()
})
})
Expand Down

0 comments on commit b8c1820

Please sign in to comment.