styled-components: props.theme is undefined when testing a component
v2.0.0-17 Everything renders fine but with create-react-app, running test:
it('renders without crashing', () => {
const div = document.createElement('div')
ReactDOM.render(<Heading />, div)
})
throws error: TypeError: Cannot read property x of undefined.
x for me is colors property of theme object passed to ThemeProvider:
const theme = {
colors: { primary, secondary, etc... }
}
Test fails because props.theme is undefined. But everything renders fine. Is this a bug?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (8 by maintainers)
@bhough @philpl I understand that wrapping the component in the
ThemeProviderwill work because of the missing context. But isn’t there a more comfortable way of testing this? You see, I don’t want to wrap every single component in aThemeProvider. Maybe there is a way setting a default context for all tests in jest/enzyme?