@@ -22,19 +22,19 @@ So we can just wrap up the thing we want to test in a different
22
22
component and stub out the ` context ` stuff.
23
23
24
24
``` 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:
26
30
var TestWrapper = React .createClass ({
27
31
childContextTypes: {
28
- router: React .PropTypes .object
32
+ router: React .PropTypes .func
29
33
},
30
34
31
35
getChildContext () {
32
- return router: {
33
- makePath () {},
34
- makeHref () {},
35
- isActive () {},
36
- // and whichever router methods your component uses
37
- }
36
+ return {
37
+ router: RouterStub
38
38
};
39
39
},
40
40
@@ -58,26 +58,30 @@ Copy/paste this helper into your test utils to make things a bit easier:
58
58
59
59
``` js
60
60
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
+
61
77
return React .createClass ({
62
78
childContextTypes: {
63
- router: object
79
+ router: React . PropTypes . func
64
80
},
65
81
66
82
getChildContext () {
67
83
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
81
85
};
82
86
},
83
87
0 commit comments