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

[1.0.0-beta.0] className assertion failing when element has multiple classNames #210

Open
dptoot opened this issue Nov 21, 2017 · 10 comments
Labels

Comments

@dptoot
Copy link

dptoot commented Nov 21, 2017

As you can see the element selection has the correct className asserted but only seems to respect the first. Any suggestions?

 AssertionError: expected the node in <div /> to have a 'glyphicon-menu-right' class, but it has 'text-link'

     HTML:

     <span class="text-link glyphicon glyphicon-menu-right"></span>
      + expected - actual

      -text-link
      +glyphicon-menu-right
@intrepidOlivia
Copy link

I am having a similar problem, except that the chai-enzyme seems to recognize all the relevant text, but still fails the test.

classname_assertion

@ljharb
Copy link
Member

ljharb commented Jul 12, 2018

@intrepidOlivia those are two class names - i'd expect you would be using two assertions, not one, to test for those.

@intrepidOlivia
Copy link

Are you sure? As you can see, the two class names on the li element are concatenated into a single string. CSS recognizes them as separate classes, but since React only ever sees one string, I don't think it'll recognize it as having multiple class names. Or do you know of documentation that suggests otherwise?

@ljharb
Copy link
Member

ljharb commented Jul 15, 2018

every API I’m familiar with that takes class names only takes one at a time, or an array.

@intrepidOlivia
Copy link

Perhaps so, but I resolved this problem by simply using vanilla enzyme's hasClass function:

react_hasclass

@ljharb
Copy link
Member

ljharb commented Jul 18, 2018

While as enzymes maintainer that surprises me, if enzyme works that way than certainly this matcher should as well.

@ljharb ljharb added the bug label Jul 18, 2018
@Hypnosphi
Copy link

It works OK with shallow, but not with mount

@ljharb
Copy link
Member

ljharb commented Dec 27, 2019

@Hypnosphi to clarify; what's the difference between the two with hasClass? they both call into the same utility function.

@Hypnosphi
Copy link

hasClass works in both cases, while should.have.className works only with shallow

@ljharb
Copy link
Member

ljharb commented Dec 28, 2019

Thanks for the clarification :-)

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

No branches or pull requests

4 participants