Last active
October 20, 2015 04:41
-
-
Save ryanflorence/1f72da0cd9e507ebec29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsx React.DOM */ | |
function makeStubbedDescriptor(component, props, contextStubs) { | |
var TestWrapper = React.createClass({ | |
childContextTypes: { | |
currentPath: React.PropTypes.string, | |
makePath: React.PropTypes.func.isRequired, | |
makeHref: React.PropTypes.func.isRequired, | |
transitionTo: React.PropTypes.func.isRequired, | |
replaceWith: React.PropTypes.func.isRequired, | |
goBack: React.PropTypes.func.isRequired, | |
isActive: React.PropTypes.func.isRequired, | |
activeRoutes: React.PropTypes.array.isRequired, | |
activeParams: React.PropTypes.object.isRequired, | |
activeQuery: React.PropTypes.object.isRequired, | |
location: React.PropTypes.object, | |
routes: React.PropTypes.array.isRequired, | |
namedRoutes: React.PropTypes.object.isRequired, | |
scrollBehavior: React.PropTypes.object | |
}, | |
getChildContext: function() { | |
return merge({ | |
currentPath: '__STUB__', | |
makePath: function() {}, | |
makeHref: function() { return '__STUB__'; }, | |
transitionTo: function() {}, | |
replaceWith: function() {}, | |
goBack: function() {}, | |
isActive: function() {}, | |
activeRoutes: [], | |
activeParams: {}, | |
activeQuery: {}, | |
location: {}, | |
routes: [], | |
namedRoutes: {}, | |
scrollBehavior: {} | |
}, contextStubs); | |
}, | |
render: function() { | |
this.props.ref = '__subject__'; | |
return component(this.props); | |
} | |
}); | |
return TestWrapper(props); | |
} | |
// usage | |
var component = React.renderComponent(makeStubbedDescriptor(App, {}), document.body); | |
// do stuff with component now and the router isn't in your way |
Its works, but I receive warnings
Warning: Required context `getCurrentPath` was not specified in `Link`. Check the render method of `TargetScan`.
Warning: Required context `getCurrentRoutes` was not specified in `Link`. Check the render method of `TargetScan`.
Warning: Required context `getCurrentPathname` was not specified in `Link`. Check the render method of `TargetScan`.
Warning: Required context `getCurrentQuery` was not specified in `Link`. Check the render method of `TargetScan`.
Warning: Required context `getCurrentPath` was not specified in `Link`. Check the render method of `TargetScan`.
Warning: Required context `getCurrentRoutes` was not specified in `Link`. Check the render method of `TargetScan`.
Warning: Required context `getCurrentPathname` was not specified in `Link`. Check the render method of `TargetScan`.
Warning: Required context `getCurrentQuery` was not specified in `Link`. Check the render method of `TargetScan`.
Can you suggest what to do?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added this:
and this:
to make it work with
RouteHandler
andState
mixins.