Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to assert a CSS attribute contains some text in Cypress test?

In my Cypress test I’m trying to assert that an element’s text is underlined.

I tried to use the below assertion:

homePage.getHeadingWidgetContent().should('have.css', 'text-decoration', 'underline');

But the actual text-decoration is 'underline solid rgba(0, 0, 0, 0.87)');

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This below assertion passes:

homePage.getHeadingWidgetContent().should('have.css', 'text-decoration', 'underline solid rgba(0, 0, 0, 0.87)');

Is there a way I can assert that text-decoration includes ‘underline’?

>Solution :

text-decoration is shorthand for a group of properties. You should use one of its constituent properties, specifically text-decoration-line.

homePage.getHeadingWidgetContent().should(
  'have.css', 'text-decoration-line', 'underline'
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading