-
Notifications
You must be signed in to change notification settings - Fork 665
Support multiple classes in hasClass
#118
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
Comments
Multi-word classes are… not a thing. It's just multiple class names! With semantic-ui, are If they're not the same thing, try |
@callumacrae Thanks for the reply. In many cases the order does have an impact in semantic-ui, but I think those are mostly weird edge cases, probably not a good use case to argue for this feature. For now I changed the title of the issue to be more understandable. I don't understand what your second comment means - I haven't seen that syntax, how can I use it to assert my wrapper has the class "complete todo" with the existing tools in vue-test-utils? Maybe I could pull another library in to do the comparison but other than doing two If it's outside of the scope of vue-test-utils that's okay too, but I feel like I should be able to do |
hasClass
hasClass
I agree that it would be useful for |
Right, thanks for the clarification. I was more concerned about checking for the full two classes being present, not so much the order - in this case 'incomplete todo' vs 'complete todo'. I know I can just workaround by checking for |
Yep we could do this @lmiller1990. Are you able to make a PR? |
Sure, will look into it this week! |
Here is my first attempt @eddyerburgh Accidentally changed stuff in Will make the PR after I've gotten your feedback had a chance to run all the tests (for some reason having problems on my windows machine running the typescript types tests). Edit: can probably make more readable by using:
What I am doing is seeing if the entire array contains the same values - all |
@lmiller1990 If you make a PR I can review it in GitHub. But it looks good so far. You can use every instead of map and reduce: targetClass.split(' ').every(target => element.classList.contains(target)) We can discuss further when you make a PR |
Done #123 @eddyerburgh |
At the moment this will return true: <template>
<div class="class-a class-b" />
</template> const wrapper = mount(Component)
wrapper.hasClass('class-b class-a') I don't think this is the behavior we want. Do others agree? |
We're handling this by using a Ex:
The other advantage this gives is clearer output on failure. With a failure on |
@eddyerburgh I disagree, I would expect the current behaviour to be the desired behaviour. It's testing that the element has those classes, not that the class attribute contains that string. Perhaps it would be clearer if the syntax were more like When order matters I'd expect something more like |
Intuitively, I don't think the order should matter - in any css lib, like boostrap, I'd usually do Although I also think @tim-hutchinson raises a valid point. I'm interested in seeing what other people think. |
Ok, I agree. Closing the issue as it's been merged 🙂 |
Hi,
I noticed that
hasClass()
only works for single word classes. For example, I did something like:And because
hasClass()
doesreturn !!(this.element && this.element.classList.contains(className))
You cannot find multiword classes. This was a little inconvenient since I mainly use semantic-ui, which uses longer multiword names like
ui eight wide compact grid
. Being able to assert the full class name makes my tests more understandable.My proposal is to all
hasClass
to work with multiword classes. This seems like a pretty easy change and I'd like to tackle it if the maintainer(s) are okay with it.The text was updated successfully, but these errors were encountered: