Skip to content

Instantly share code, notes, and snippets.

@cmain
Created March 27, 2015 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmain/69aee0b5d9cab96589d7 to your computer and use it in GitHub Desktop.
Save cmain/69aee0b5d9cab96589d7 to your computer and use it in GitHub Desktop.
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