Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

styled-components version 5+ causing invalid hooks call error with enzyme's .dive() and .shallow() #3037

Closed
manveers96 opened this issue Feb 25, 2020 · 5 comments

Comments

@manveers96
Copy link

Environment

System:

  • OS: macOS Mojave 10.14
  • CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  • Memory: 495.23 MB / 16.00 GB
  • Shell: 5.3 - /bin/zsh

Binaries:

  • Node: 10.9.0 - ~/.nvm/versions/node/v10.9.0/bin/node
  • Yarn: 1.16.0 - ~/.yarn/bin/yarn
  • npm: 6.9.2 - ~/.nvm/versions/node/v10.9.0/bin/npm

Issue Description

I recently upgraded from styled-components@4.3.2 to styled-components@5.0.1 and am getting an invalid Hook call error at a place where I'm using .dive() function of enzyme.
I was not getting this error with the previous version of styled-components@4.3.2. Probably, the error has been introduced after styled-components updated from 4.4.1 to 5.0.0 in which I can see one of the PRs as Reimplement StyledComponent using hooks #2390. I'm using enzyme's .dive() function in setting up the snapshots for my React components.

Can we have a look at why we might be getting this issue?

PS: This issue occurs with .shallow() function also. I've also upgraded jest-styled-components to 7.0.0

@andreyluiz
Copy link

@manveers96 Have you been able to go around this problem? Or do you still have it?

@goroya
Copy link

goroya commented Aug 26, 2020

me too

@manveers96
Copy link
Author

@andreyluiz Was not able to0 find a solution for this problem. Tried the workaround suggested by Dan Abramov over here: facebook/react#15315 (comment) but this was not the case for my app as I had a single version of react being used according to the bundler. I checked this using npm ls react.

If anyone has any fix for this, please suggest.

@Gi-Totev
Copy link

Gi-Totev commented Jun 9, 2021

I had the same problem, turns out I installed styled-components in the parent folder of the project and not in the create-react-app folder. Deleted styled-components, cd [react-app], npm install styled-components and the error is gone

@kitten kitten closed this as completed Aug 9, 2021
@hhnssl
Copy link

hhnssl commented Jul 10, 2022

I had the same problem, turns out I installed styled-components in the parent folder of the project and not in the create-react-app folder. Deleted styled-components, cd [react-app], npm install styled-components and the error is gone

thanks a lot. i solved my problem refer to your comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants