Skip to content

Commit

Permalink
Merge pull request #2813 from rackt/match-history
Browse files Browse the repository at this point in the history
Add passing custom histories to match
  • Loading branch information
timdorr committed Jan 1, 2016
2 parents 050544f + f21914b commit 8ca933e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion modules/__tests__/serverRendering-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import expect from 'expect'
import expect, { spyOn } from 'expect'
import React, { Component } from 'react'
import { renderToString } from 'react-dom/server'
import match from '../match'
import createMemoryHistory from '../createMemoryHistory'
import RouterContext from '../RouterContext'
import Link from '../Link'

Expand Down Expand Up @@ -75,6 +76,21 @@ describe('server rendering', function () {
})
})

it('accepts a custom history', function (done) {
const history = createMemoryHistory()
const spy = spyOn(history, 'createLocation').andCallThrough()

match({ history, routes, location: '/dashboard' }, function (error, redirectLocation, renderProps) {
const string = renderToString(
<RouterContext {...renderProps} />
)
expect(string).toMatch(/The Dashboard/)
expect(spy).toHaveBeenCalled()
done()
})
})


it('renders active Links as active', function (done) {
match({ routes, location: '/about' }, function (error, redirectLocation, renderProps) {
const string = renderToString(
Expand Down
4 changes: 2 additions & 2 deletions modules/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { createRouterObject, createRoutingHistory } from './RouterUtils'
* Note: You probably don't want to use this in a browser. Use
* the history.listen API instead.
*/
function match({ routes, location, ...options }, callback) {
function match({ history, routes, location, ...options }, callback) {
invariant(
location,
'match needs a location'
)

let history = createMemoryHistory(options)
history = history ? history : createMemoryHistory(options)
const transitionManager = createTransitionManager(
history,
createRoutes(routes)
Expand Down

0 comments on commit 8ca933e

Please sign in to comment.