To assert the CSS pseudo-selector ::before in Cypress, you can use the cy.get
command with the invoke
method to retrieve the computed style of the ::before element and assert its value.
For example, if you have the following CSS rule applied to an HTML element:
.some-element::before {
content: "Before";
color: red;
}
You can assert the content of the ::before element using Cypress like this:
cy.get('.some-element::before').invoke('css', 'content').should('eq', '"Before"')
And you can assert the color like this:
cy.get('.some-element::before').invoke('css', 'color').should('eq', 'rgb(255, 0, 0)')
Asked: 2023-05-16 02:28:01 +0000
Seen: 12 times
Last updated: May 16 '23