Closed joetidee closed 5 years ago
You might have multiple copies of styled-components loading in your tests... happens often. You can use moduleNameMapper
in jest to dedupe it.
OK, i added:
moduleNameMapper: {
'^styled-components$': '<rootDir>/node_modules/styled-components'
},
and the tests are now working - thank you @probablyup . Why does Jest load multiple copies? Is this specific to styled components, else how is it not loading multiple copies of other modules used?
Probably you’re using two libraries with s-c in dependencia but it’s only meant to be installed once. The shared library should specify it as a peer dependency
On Sun, Aug 25, 2019 at 7:18 AM Joe notifications@github.com wrote:
OK, i added:
moduleNameMapper: { '^styled-components$': '
/node_modules/styled-components' }, and the tests are now working - thank you @probablyup https://github.com/probablyup . Why does Jest load multiple copies? Is this specific to styled components, else how is it not loading multiple copies of other modules used?
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/styled-components/styled-components/issues/2724?email_source=notifications&email_token=AAELFVVBBPBFUXUZTJM73JLQGJTB3A5CNFSM4IOKQUS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5CRQTY#issuecomment-524621903, or mute the thread https://github.com/notifications/unsubscribe-auth/AAELFVTLTUATTQNLZ6JZUZDQGJTB3ANCNFSM4IOKQUSQ .
Probably you’re using two libraries with s-c in dependencia but it’s only meant to be installed once. The shared library should specify it as a peer dependency … On Sun, Aug 25, 2019 at 7:18 AM Joe @.***> wrote: OK, i added: moduleNameMapper: { '^styled-components$': '
/node_modules/styled-components' }, and the tests are now working - thank you @probablyup https://github.com/probablyup . Why does Jest load multiple copies? Is this specific to styled components, else how is it not loading multiple copies of other modules used? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2724?email_source=notifications&email_token=AAELFVVBBPBFUXUZTJM73JLQGJTB3A5CNFSM4IOKQUS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5CRQTY#issuecomment-524621903>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAELFVTLTUATTQNLZ6JZUZDQGJTB3ANCNFSM4IOKQUSQ .
So, I am using a monorepo with a ui
and web
layer. Both layers have styled-components
as dependencies. The web
layer also has the ui
layer as a dependency. So, what, if anythgin do I change to a peerDependency?
The upstream packages should have styled-components
as a peerDependency and the downstream ones should declare it as a dependency.
I have just upgraded from v3 to v4 and now when running my Jest/Enzyme tests I get the following messages:
This seems to suggest that the theme prop is not getting to my
Icon
component. Nothing has changed in the way that I am supplying the theme to my components in the tests and they were all working before upgrading.const component = mount(<Wrapper store={store}><RootComponent {...props} /></Wrapper>, rootWrappers);
With
Wrapper
being:and
ThemeProvider
being:Packages used: react 16.8.6 enzyme 3.10.0 jest: 24.9.0 jest-styled-components: 6.3.3 styled-components: 4.3.2