Ask Your Question
1

What is the way to assert ::before in Cypress?

asked 2023-05-16 02:28:01 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-16 02:42:01 +0000

huitzilopochtli gravatar image

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)')
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-16 02:28:01 +0000

Seen: 12 times

Last updated: May 16 '23