Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// This helper is required to test any component that renders material-ui components.
// If you are getting a message saying:
// 'undefined is not an object (evaluating this.context.muiTheme.prepareStyles)'
// you should use this helper.
// The usage is simple, you pass a component class to extendComponentWithMUITheme
// and it will return a new component class capable of rendering material-ui
// components
// const MyExtendedComponent = extendComponentWithMUITheme(MyComponent)
// ReactTestUtils.renderIntoDocument(<MyExtendedComponent />)
import { PropTypes } from 'react'
import { getMuiTheme } from 'material-ui/styles'
export default function extendComponentWithMUITheme (component) {
return class ExtendedComponentWithMUITheme extends component {
static childContextTypes = {
muiTheme: PropTypes.object
}
getChildContext () {
return {
muiTheme: getMuiTheme()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.