Skip to content

Commit

Permalink
React 16 support
Browse files Browse the repository at this point in the history
Code was fine, tests needed some changes.

GREAT JOB REACT TEAM

11 tests failed initially. The tests needed to adjust how they handled a few async things, but they are unlikely to be problems in application code.
  • Loading branch information
ryanflorence committed Sep 12, 2017
1 parent 4816eca commit b0a9c75
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 61 deletions.
16 changes: 10 additions & 6 deletions modules/__tests__/Link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe('A <Link>', () => {
<Route path="hello" component={Hello} />
</Route>
</Router>
), node, execNextStep)
), node)
})

it('has its activeStyle', done => {
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('A <Link>', () => {
<Route path="goodbye" component={Goodbye} />
</Route>
</Router>
), node, execNextStep)
), node)
})
})

Expand Down Expand Up @@ -295,7 +295,7 @@ describe('A <Link>', () => {
<Route path="hello" component={Hello} />
</Route>
</Router>
), node, execNextStep)
), node)
})

it('changes active state inside static containers', done => {
Expand Down Expand Up @@ -323,7 +323,11 @@ describe('A <Link>', () => {
history.push('/hello')
},
() => {
expect(a.className).toEqual('active')
// React 16 has slightly different update timing so we'll just sorta
// punt a bit with a setTimeout.
setTimeout(() => {
expect(a.className).toEqual('active')
}, 10)
}
]

Expand Down Expand Up @@ -393,7 +397,7 @@ describe('A <Link>', () => {
<Route path="/" component={LinkWrapper} />
<Route path="/hello" component={Hello} />
</Router>
), node, execNextStep)
), node)
})

it('transitions to the correct route for object', done => {
Expand Down Expand Up @@ -435,7 +439,7 @@ describe('A <Link>', () => {
<Route path="/" component={LinkWrapper} />
<Route path="/hello" component={Hello} />
</Router>
), node, execNextStep)
), node)
})

it('does not transition when onClick prevents default', done => {
Expand Down
15 changes: 7 additions & 8 deletions modules/__tests__/Router-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,13 @@ describe('Router', function () {
})
})

it('should throw without onError', function () {
expect(function () {
render((
<Router history={createHistory('/')}>
<Route path="/" getComponent={getComponent} />
</Router>
), node)
}).toThrow('error fixture')
it('should throw without onError', function (done) {
const callback = expect(() => { done() }).toThrow('error fixture')
render((
<Router history={createHistory('/')}>
<Route path="/" getComponent={getComponent} />
</Router>
), node, callback)
})
})
})
6 changes: 1 addition & 5 deletions modules/__tests__/RouterContext-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,13 @@ describe('RouterContext', () => {
})
}

describe('2.0', () => {
it('exports only `router` to context')
})

it('exports a `router` object to routing context', (done) => {
renderTest(() => {
expect(context.router).toExist()
done()
})
})

it('injects a `router` object into props of route components', (done) => {
class RoutedComponent extends React.Component {
render() {
Expand Down
2 changes: 1 addition & 1 deletion modules/__tests__/push-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('push', () => {
<Route path="/" component={Index}/>
<Route path="/home/hi:there" component={Home}/>
</Router>
), node, execNextStep)
), node)
})
})

Expand Down
48 changes: 32 additions & 16 deletions modules/__tests__/transitionHooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,43 @@ describe('When a router enters a branch', function () {
it('calls the route leave hooks when leaving the route', function (done) {
const history = createHistory('/news')

render(<Router history={history} routes={routes}/>, node, function () {
expect(newsLeaveHookSpy.calls.length).toEqual(0)
history.push('/inbox')
expect(newsLeaveHookSpy.calls.length).toEqual(1)
history.push('/news')
expect(newsLeaveHookSpy.calls.length).toEqual(1)
history.push('/inbox')
expect(newsLeaveHookSpy.calls.length).toEqual(2)
done()
})
const steps = [
() => {
expect(newsLeaveHookSpy.calls.length).toEqual(0)
history.push('/inbox')
},
() => {
expect(newsLeaveHookSpy.calls.length).toEqual(1)
history.push('/news')
},
() => {
expect(newsLeaveHookSpy.calls.length).toEqual(1)
history.push('/inbox')
},
() => {
expect(newsLeaveHookSpy.calls.length).toEqual(2)
}
]

const execNextStep = execSteps(steps, done)

render(<Router history={history} routes={routes} onUpdate={execNextStep}/>, node)
})

it('does not call removed route leave hooks', function (done) {
const history = createHistory('/news')

render(<Router history={history} routes={routes}/>, node, function () {
removeNewsLeaveHook()
history.push('/inbox')
expect(newsLeaveHookSpy).toNotHaveBeenCalled()
done()
})
const execNextStep = execSteps([
() => {
removeNewsLeaveHook()
history.push('/inbox')
},
() => {
expect(newsLeaveHookSpy).toNotHaveBeenCalled()
}
], done)

render(<Router history={history} routes={routes} onUpdate={execNextStep}/>, node)
})

it('does not remove route leave hooks when changing params', function (done) {
Expand Down
24 changes: 17 additions & 7 deletions modules/__tests__/withRouter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import createHistory from '../createMemoryHistory'
import Route from '../Route'
import Router from '../Router'
import withRouter from '../withRouter'
import execSteps from './execSteps'

describe('withRouter', function () {
const routerStub = {
Expand Down Expand Up @@ -114,19 +115,28 @@ describe('withRouter', function () {

const history = createHistory('/')

const execNextStep = execSteps([
() => {
expect(node.firstChild.textContent).toEqual('/')
history.push('/hello')
},
() => {
// React 16 has slightly different update timing so we'll just sorta
// punt a bit with a setTimeout.
setTimeout(() => {
expect(node.firstChild.textContent).toEqual('/hello')
}, 10)
}
], done)

render((
<Router history={history}>
<Router history={history} onUpdate={execNextStep}>
<Route component={StaticContainer}>
<Route path="/" component={WrappedApp} />
<Route path="/hello" component={WrappedApp} />
</Route>
</Router>
), node, function () {
expect(node.firstChild.textContent).toEqual('/')
history.push('/hello')
expect(node.firstChild.textContent).toEqual('/hello')
done()
})
), node)
})

it('should render Component even without Router context', function (done) {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-router",
"version": "3.0.5",
"version": "3.1.0-rc.1",
"description": "A complete routing library for React",
"files": [
"*.md",
Expand Down Expand Up @@ -42,7 +42,7 @@
"warning": "^3.0.0"
},
"peerDependencies": {
"react": "^0.14.0 || ^15.0.0"
"react": "^0.14.0 || ^15.0.0 || ^16.0.0-rc"
},
"devDependencies": {
"babel-cli": "^6.11.4",
Expand Down Expand Up @@ -79,9 +79,9 @@
"mocha": "^3.2.0",
"pretty-bytes": "^4.0.2",
"qs": "^6.2.1",
"react": "^15.5.3",
"react-dom": "^15.5.3",
"react-transition-group": "^1.1.1",
"react": "^16.0.0-rc",
"react-addons-css-transition-group": "^15.6.0",
"react-dom": "^16.0.0-rc",
"rimraf": "^2.5.4",
"style-loader": "^0.16.1",
"webpack": "^1.13.1",
Expand Down
34 changes: 21 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3160,7 +3160,7 @@ longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"

loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0:
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
dependencies:
Expand Down Expand Up @@ -3971,7 +3971,7 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

prop-types@^15.5.2, prop-types@^15.5.6, prop-types@~15.5.0:
prop-types@^15.5.6:
version "15.5.6"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.6.tgz#797a915b1714b645ebb7c5d6cc690346205bd2aa"
dependencies:
Expand Down Expand Up @@ -4068,31 +4068,39 @@ rc@^1.1.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-dom@^15.5.3:
version "15.5.3"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.5.3.tgz#2ee127ce942df55da53111ae303316e68072b5c5"
react-addons-css-transition-group@^15.6.0:
version "15.6.0"
resolved "https://registry.yarnpkg.com/react-addons-css-transition-group/-/react-addons-css-transition-group-15.6.0.tgz#69887cf6e4874d25cd66e22a699e29f0d648aba0"
dependencies:
react-transition-group "^1.2.0"

react-dom@^16.0.0-rc:
version "16.0.0-rc.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.0.0-rc.2.tgz#f94dc1c350acd67284233558996a8293d7aa99c7"
dependencies:
fbjs "^0.8.9"
loose-envify "^1.1.0"
object-assign "^4.1.0"
prop-types "~15.5.0"
prop-types "^15.5.6"

react-transition-group@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-1.1.1.tgz#f9d0f0dff82f52574fc5ab30684add24948d0f23"
react-transition-group@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-1.2.0.tgz#b51fc921b0c3835a7ef7c571c79fc82c73e9204f"
dependencies:
chain-function "^1.0.0"
dom-helpers "^3.2.0"
loose-envify "^1.3.1"
prop-types "^15.5.6"
warning "^3.0.0"

react@^15.5.3:
version "15.5.3"
resolved "https://registry.yarnpkg.com/react/-/react-15.5.3.tgz#84055382c025dec4e3b902bb61a8697cc79c1258"
react@^16.0.0-rc:
version "16.0.0-rc.2"
resolved "https://registry.yarnpkg.com/react/-/react-16.0.0-rc.2.tgz#1e55cc18fd9c56260f1d0ccf9caca6d3152dc83c"
dependencies:
fbjs "^0.8.9"
loose-envify "^1.1.0"
object-assign "^4.1.0"
prop-types "^15.5.2"
prop-types "^15.5.6"

read-pkg-up@^1.0.1:
version "1.0.1"
Expand Down

0 comments on commit b0a9c75

Please sign in to comment.