Jest-styled-components: Type Error: Cannot read property 'withConfig' of undefined

Created on 17 Apr 2018  路  4Comments  路  Source: styled-components/jest-styled-components

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

react native

Most helpful comment

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'

All 4 comments

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/native instead of jest-styled-components.

I have the same problem.
"jest": "^25.1.0",
"jest-styled-components": "^7.0.3",
"styled-components": "^5.1.1",

Was this page helpful?
0 / 5 - 0 ratings