Since router relies heavily on React's lesser-known context function, you need to drown it out as described here
var stubRouterContext = (Component, props, stubs) => { return React.createClass({ childContextTypes: { makePath: func, makeHref: func, transitionTo: func, replaceWith: func, goBack: func, getCurrentPath: func, getCurrentRoutes: func, getCurrentPathname: func, getCurrentParams: func, getCurrentQuery: func, isActive: func, }, getChildContext () { return Object.assign({ makePath () {}, makeHref () {}, transitionTo () {}, replaceWith () {}, goBack () {}, getCurrentPath () {}, getCurrentRoutes () {}, getCurrentPathname () {}, getCurrentParams () {}, getCurrentQuery () {}, isActive () {}, }, stubs); }, render () { return <Component {...props} /> } }); };
And use like:
var stubRouterContext = require('./stubRouterContext'); var IndividualComponent = require('./IndividualComponent'); var Subject = stubRouterContext(IndividualComponent, {someProp: 'foo'}); React.render(<Subject/>, testElement);
Yevgen safronov
source share