Ask Your Question

Revision history [back]

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)')