I'm using styled-components 3.0.2 and jest-styled-components 5.0.1 with config in my package.json
"jest": {
"preset": "react-native",
"setupFiles": [
"./tests/setup/configEnzyme.js"
],
"setupTestFrameworkScriptFile": "./tests/setup/configStyledComponent.js",
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
}
when I import component such as
MyComponent = styled.View`
background-color: 'red';
`
to my test, I'll got error
TypeError: Cannot read property 'withConfig' of undefined
but if MyComponent look like
MyComponent = styled(View)`
background-color: 'red';
`
everything works
Same issue on a RN app with styled-components.
What I get:
TypeError: Cannot read property 'withConfig' of undefined
6 |
> 7 | const Wrap = styled.View`
| ^
8 | justify-content: center;
9 | background-color: #f6f7fa;
10 | border-radius: 5px;
my problem was using:
import styled from 'styled-components'
import 'jest-styled-components'
instead of the native counterparts:
import styled from 'styled-components/native'
import 'jest-styled-components/native'
I am having the same problem after importing jest-styled-components/native instead of jest-styled-components.
I am having the same problem after importing
jest-styled-components/nativeinstead ofjest-styled-components.
I have the same problem.
"jest": "^25.1.0",
"jest-styled-components": "^7.0.3",
"styled-components": "^5.1.1",
Most helpful comment
my problem was using:
instead of the native counterparts: