Skip to content

Commit 06c15c5

Browse files
committed
Fix router stubbing docs for RR 0.13
1 parent c59c46f commit 06c15c5

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

docs/guides/testing.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ So we can just wrap up the thing we want to test in a different
2222
component and stub out the `context` stuff.
2323

2424
```js
25-
// wrap it up first:
25+
// add whichever router methods your component uses:
26+
function RouterStub() { }
27+
RouterStub.makePath = function () { }
28+
29+
// wrap it up:
2630
var TestWrapper = React.createClass({
2731
childContextTypes: {
28-
router: React.PropTypes.object
32+
router: React.PropTypes.func
2933
},
3034

3135
getChildContext () {
32-
return router: {
33-
makePath () {},
34-
makeHref () {},
35-
isActive () {},
36-
// and whichever router methods your component uses
37-
}
36+
return {
37+
router: RouterStub
3838
};
3939
},
4040

@@ -58,26 +58,30 @@ Copy/paste this helper into your test utils to make things a bit easier:
5858

5959
```js
6060
var stubRouterContext = (Component, props, stubs) => {
61+
function RouterStub() { }
62+
63+
Object.assign(RouterStub, {
64+
makePath () {},
65+
makeHref () {},
66+
transitionTo () {},
67+
replaceWith () {},
68+
goBack () {},
69+
getCurrentPath () {},
70+
getCurrentRoutes () {},
71+
getCurrentPathname () {},
72+
getCurrentParams () {},
73+
getCurrentQuery () {},
74+
isActive () {},
75+
}, stubs)
76+
6177
return React.createClass({
6278
childContextTypes: {
63-
router: object
79+
router: React.PropTypes.func
6480
},
6581

6682
getChildContext () {
6783
return {
68-
router: Object.assign({
69-
makePath () {},
70-
makeHref () {},
71-
transitionTo () {},
72-
replaceWith () {},
73-
goBack () {},
74-
getCurrentPath () {},
75-
getCurrentRoutes () {},
76-
getCurrentPathname () {},
77-
getCurrentParams () {},
78-
getCurrentQuery () {},
79-
isActive () {},
80-
}, stubs)
84+
router: RouterStub
8185
};
8286
},
8387

0 commit comments

Comments
 (0)