question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] add expect(locator).toContainClass()

See original GitHub issue

Hi 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:open
  • Created a year ago
  • Reactions:6
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bboylecommented, Aug 29, 2022

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 😃

1reaction
mxschmittcommented, May 13, 2022

@Diokuz we can add toContainClass for that.

Are you interested in contributing this feature? Then let us know!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found