Permalink
Browse files

React 16 support

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...
1 parent 4816eca commit b0a9c75960eef1f9f915f4581667ed8025032410 @ryanflorence ryanflorence committed Sep 12, 2017
@@ -221,7 +221,7 @@ describe('A <Link>', () => {
<Route path="hello" component={Hello} />
</Route>
</Router>
- ), node, execNextStep)
+ ), node)
})
it('has its activeStyle', done => {
@@ -260,7 +260,7 @@ describe('A <Link>', () => {
<Route path="goodbye" component={Goodbye} />
</Route>
</Router>
- ), node, execNextStep)
+ ), node)
})
})
@@ -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 => {
@@ -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)
}
]
@@ -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 => {
@@ -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 => {
@@ -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)
})
})
})
@@ -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() {
@@ -45,7 +45,7 @@ describe('push', () => {
<Route path="/" component={Index}/>
<Route path="/home/hi:there" component={Home}/>
</Router>
- ), node, execNextStep)
+ ), node)
})
})
@@ -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) {
@@ -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 = {
@@ -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) {
View
@@ -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",
@@ -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",
@@ -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",
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit b0a9c75

Please sign in to comment.