-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Unexpected behaviour of .hasClass()
aka. Ability to use .hasClass()
on React Components
#307
Comments
@EvNaverniouk this is indeed supposed to work this way. I think maybe adding it to common gotchas would make sense though...
This is essentially treating |
Thanks for that explanation. Sounds like "Option C" is the way to go then. |
I ran across this issue today while making a presentation at a local group. Not too cool. Of course shallow rendering works as expected while a mount fails as described above so I am voting +1. |
This issue may be resolved now by #677. @EvNaverniouk can you test from the master branch to verify? |
Closed by #677 - let's reopen if there's still an issue. |
I was having a lot of trouble using the
hasClass()
method. It appeared to work sometimes, but not other times. Until I finally realized what was going wrong through trial and error.Here is a very simple code sample where it doesn't work as expected.
After some thinking, I discovered that this is because
hasClass()
only works on regular DOM nodes and not on React Components. So I tried:Is there any reason
hasClass()
was designed this way? My original code makes logical sense to me, but didn't work as I expected.My recommendations are (in order of preference):
hasClass()
to work on React Components and have it look for the class name in the top-level DOM node, orhasClass()
to not work at all on React Components so that users aren't surprised by this behaviour, orThe text was updated successfully, but these errors were encountered: