Created
June 4, 2015 00:23
-
-
Save jbasdf/81e95f54f21389bfcdf2 to your computer and use it in GitHub Desktop.
Stub context for React Router and Material UI >= 0.8.0
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
"use strict"; | |
import React from "react"; | |
import assign from "object-assign"; | |
var { func } = React.PropTypes; | |
var mui = require('material-ui'); | |
var ThemeManager = new mui.Styles.ThemeManager(); | |
export default (Component, props, stubs) => { | |
function RouterStub(){ } | |
assign(RouterStub, { | |
makePath(){}, | |
makeHref(){}, | |
transitionTo(){}, | |
replaceWith(){}, | |
goBack(){}, | |
getCurrentPath(){}, | |
getCurrentRoutes(){}, | |
getCurrentPathname(){}, | |
getCurrentParams(){}, | |
getCurrentQuery(){}, | |
isActive(){}, | |
getRouteAtDepth(){}, | |
setRouteComponentAtDepth(){} | |
}, stubs); | |
class Stubber extends React.Component { | |
getChildContext(){ | |
return { | |
router: RouterStub, | |
routeDepth: 0, | |
muiTheme: ThemeManager.getCurrentTheme() | |
}; | |
} | |
// Use to get access to the component instance in case you need to spyOn a method of the component. | |
originalComponent(){ | |
return this.refs.originalComponent; | |
} | |
render(){ | |
return <Component ref="originalComponent" {...props} />; | |
} | |
} | |
Stubber.childContextTypes = { | |
router: React.PropTypes.func, | |
routeDepth: React.PropTypes.number, | |
muiTheme: React.PropTypes.object | |
}; | |
return Stubber; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment