Created
July 17, 2015 15:42
-
-
Save MicheleBertoli/5482811aa2942709c063 to your computer and use it in GitHub Desktop.
If you want to test a react 0.13.3 component and you are using the react-router 0.13.3, you need this:
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
import React, {Component} from 'react'; | |
export default ReactRouterContext = (Element) => { | |
class RouterStub {} | |
RouterStub.makePath = () => {}; | |
RouterStub.makeHref = () => {}; | |
RouterStub.transitionTo = () => {}; | |
RouterStub.replaceWith = () => {}; | |
RouterStub.goBack = () => {}; | |
RouterStub.getCurrentPath = () => {}; | |
RouterStub.getCurrentRoutes = () => {}; | |
RouterStub.getCurrentPathname = () => {}; | |
RouterStub.getCurrentParams = () => {}; | |
RouterStub.getCurrentQuery = () => {}; | |
RouterStub.isActive = () => {}; | |
RouterStub.getRouteAtDepth = () => {}; | |
RouterStub.setRouteComponentAtDepth = () => {}; | |
class StubbedComponent extends Component { | |
getChildContext() { | |
return { | |
router: RouterStub, | |
routeDepth: 0 | |
}; | |
} | |
render() { | |
return <Element {...this.props} />; | |
} | |
} | |
StubbedComponent.childContextTypes = { | |
router: React.PropTypes.func, | |
routeDepth: React.PropTypes.number | |
}; | |
return StubbedComponent; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment