[Feature] add expect(locator).toContainClass()
See original GitHub issueHi there)
I have a strange behavior with toHaveClass assertion.
I have an html
<label class="MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined MuiFormLabel-root MuiFormLabel-colorPrimary Mui-error css-1958la6-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" for="mui-1" id="mui-1-label"></label>
And I have assertion:
await expect(label).toHaveClass('Mui-error')
which fails, but this one is good:
await expect(label).toHaveClass('MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined MuiFormLabel-root MuiFormLabel-colorPrimary Mui-error css-1958la6-MuiFormLabel-root-MuiInputLabel-root')
Is that intended?
I expected toHaveClass
be like: “Hey, label, do you have class Mui-error in your bag?”, but instead I have “Hey, label, do you have exactly one class and is it Mui-error?”.
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Check if element class contains string using playwright
I am trying to get the element of day 18, and check if it has disabled on its class. <div class="react-datepicker__day react-datepicker__ ...
Read more >[Feature] add expect(locator).isInViewport ... - GitHub
My use-case from #13131: I have a sidebar in my app which, when collapsed, animates out of the viewport using transform: translateX(-100%) (see...
Read more >Playwright Assert Element To Have Class - ProgramsBuzz
await expect(locator).toHaveClass(/active active-trail/);. You can also match using regular expressions and give newly added classes.
Read more >playwright-expect - Yevhen Laichenkov
The playwright-expect is an assertion library for TypeScript and JavaScript intended for use with a test runner such as Jest or Playwright Test....
Read more >Demo: Dynamic Citations — citeproc-js 1.1.73 documentation
Click on the chevrons to open a citation widget, select one or more references, and press “Save” to add them to the document....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
noting that
.toHaveClass(/(^|\s)active(\s|$)/)
is a more reliable workaround, but would really love the simpler API proposed here! Working with an angular app and the material library and elements have a lot of classes, I really only want to test for a specific one (e.g. is the “active” class present or not), preferably without the hard to read regex 😃@Diokuz we can add
toContainClass
for that.Are you interested in contributing this feature? Then let us know!