user-interfacecypressui-automationui-testingline-through

Cypress checking line-through


I have a web page where the items when checked get a line-through as in the image below.

Before checking:

<li style="text-decoration: none;">test</li>

After checking:

<li style="text-decoration: line-through;">test</li>

enter image description here

I am trying to assert on the line-though with :

cy.get('li').should('have.css', 'text-decoration', 'line-through')

But, I get this error on assertion :

assertexpected <li> to have CSS property text-decoration with the value line-through, but the value was line-through solid rgb(0, 0, 0)

How do I assert on the line-through?


Solution

  • You need a partial check.

    I know this works Cypress.$(e).css('text-decoration').includes('line-through') so perhaps this:

    cy.get('li')
      .invoke('css', 'text-decoration')
      .should('include', 'line-through')