Could neither find styled-components secret internals
thomasdittmar opened this issue · comments
thomasdittmar commented
Hi all,
I know that this issue has been posted before and the solution was to update the library but I even with the newer version I see that error while by just importing import 'jest-styled-components'
Here are the installed versions:
"react": "16.13.1",
"react-native": "0.63.1",
"styled-components": "5.2.1"
"jest-styled-components": "7.0.2",
"react-test-renderer": "^17.0.1"
Jest settings:
"jest": {
"preset": "react-native",
"setupFilesAfterEnv": [
"<rootDir>/../../../node_modules/react-native-gesture-handler/jestSetup.js",
"./jest/setup.js"
],
"resolver": "./jest/resolver.js",
"transform": {
"^.+\\.(js|tsx?)$": "<rootDir>/../../../node_modules/react-native/jest/preprocessor.js",
"^.+\\.(js|jsx)$": "<rootDir>/../../../node_modules/babel-jest"
},
"transformIgnorePatterns": [
"<rootDir>/../../../node_modules/(?!(react-native|nanoid|react-native-.*|react-navigation-.*|@react-navigation|@react-native-.*|redux-persist|@sentry/*)/)"
],
"moduleFileExtensions": [
"native.ts",
"native.tsx",
"native.js",
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
resolver.js
module.exports = require('jest-enhanced-resolve').default({
mainFields: ['react-native', 'main']
})
setup.js
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
My Test:
import React from 'react'
import { create } from 'react-test-renderer'
import 'jest-styled-components'
import { Box } from '../components/Box'
describe('Box component', () => {
test('Matches the snapshot', () => {
const button = create(
<Box />
)
expect(button.toJSON()).toMatchSnapshot()
})
})
Error:
● Test suite failed to run
Could neither find styled-components secret internals
at Object.<anonymous> (node_modules/jest-styled-components/src/utils.js:5:9)
at Object.<anonymous> (node_modules/jest-styled-components/src/index.js:5:19)
Is there a work-around for that issue? I really need to Snapshot
my components urgently!
Thanks
JTMCaplin commented
Did you ever find an answer for this? Having the same problem
Justin Brûlotte commented
Have the same setup and same problem :(
Eduardo Marques Nepomuceno commented
same error here!!
Chris Webb commented
same