-
Notifications
You must be signed in to change notification settings - Fork 389
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
feat: Support for regular expressions in toHaveClass #563
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #563 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 668 676 +8
Branches 254 261 +7
=========================================
+ Hits 668 676 +8 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
🎉 This PR is included in version 6.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What:
Enhances
.toHaveClass
to also support receiving regular expressions in its params, to be matched against the target element's class names.Since this is a newly supported argument type, this is not a breaking change. Any code calling
.toHaveClass
with strings only (the only supported use so far) that code will continue to work as before.Why:
Closes #556
It enables more freedom when checking an element's class names. For instance, in some preprocessed CSS scenarios, class names are generated programmatically, and the writer of the test cannot know in advance the exact class name, though they may know a substring or pattern in it.
How:
By checking, in a handful of places of the relevant code, whether a value is a string or a regular expression. If it is a regular expression, then we do a different check.
Also, in the particular case of passing
{exact:true}
options to.toHaveClass
, we disable regular expressions support, and throw an error if regular expressions are found in the arguments.Checklist: