Last active
October 10, 2022 04:37
-
-
Save jaketrent/f68028eedd4f1ddf7997 to your computer and use it in GitHub Desktop.
React-router stub context (for testing)
This file contains 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
// from https://github.com/rackt/react-router/blob/master/docs/guides/testing.md | |
var assign = require("react/lib/Object.assign"); | |
var React = require("react"); | |
var func = React.PropTypes.func; | |
module.exports = (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 assign({ | |
makePath () {}, | |
makeHref () {}, | |
transitionTo () {}, | |
replaceWith () {}, | |
goBack () {}, | |
getCurrentPath () {}, | |
getCurrentRoutes () {}, | |
getCurrentPathname () {}, | |
getCurrentParams () { return {};}, | |
getCurrentQuery () { return {}; }, | |
isActive () {} | |
}, stubs); | |
}, | |
render () { | |
return ( | |
<Component {...props} /> | |
); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment