Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stub router context for react router 0.13.2
/**
* From https://github.com/rackt/react-router/blob/master/docs/guides/testing.md
*
* var stubRouterContext = require('./stubRouterContext');
* var IndividualComponent = require('./IndividualComponent');
* var Subject = stubRouterContext(IndividualComponent, {someProp: 'foo'});
* React.render(<Subject/>, testElement);
*/
/* jshint quotmark:false */
'use strict';
var React = require('react');
var stubRouter = React.createClass({
makePath: function() {},
makeHref: function() {},
transitionTo: function() {},
replaceWith: function() {},
goBack: function() {},
getCurrentPath: function() {},
getCurrentRoutes: function() {},
getCurrentPathname: function() {},
getCurrentParams: function() {},
getCurrentQuery: function() {},
isActive: function() {},
render: function() {}
});
var stubRouterContext = (Component, props) => {
return React.createClass({
childContextTypes: {
router: React.PropTypes.func
},
getChildContext () {
return {
router: stubRouter
};
},
render () {
return <Component {...props} />;
}
});
};
module.exports = stubRouterContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment