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

.toHaveClass custom matcher #2

Closed
gnapse opened this issue Apr 6, 2018 · 2 comments · Fixed by #4
Closed

.toHaveClass custom matcher #2

gnapse opened this issue Apr 6, 2018 · 2 comments · Fixed by #4

Comments

@gnapse
Copy link
Member

gnapse commented Apr 6, 2018

At risk of sounding like I want to bloat the set of custom matchers provided by this lib, I'd like to propose .toHaveClass('dropdown-toggle'). The class attribute in html is designed to have multiple classes encoded in it, and it's often nice to be able to reliably check if an element has a certain class while ignoring the rest of what's encoded in the class attribute value.

// ...
// <button data-testid="delete-button" type="submit" class="btn btn-danger">
//   Delete item
// </button>
expect(getByTestId('delete-button')).toHaveClass('btn-danger')

Raising it as an issue first to see if it's considered useful for this lib, and also to discuss potential names:

  • toHaveClass
  • toIncludeClass
  • toContainClass
  • something else?

Or all of the above but ending with *ClassName instead of just *Class.

@kentcdodds
Copy link
Member

Sounds good to me. I like toHaveClass 👍

kentcdodds pushed a commit that referenced this issue Apr 7, 2018
* Add toHaveClass custom matcher

* Add documentation in the README

* Handle the case where an element has no class
@kentcdodds
Copy link
Member

🎉 This issue has been resolved in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants