https://cypress.io logo
OR assertion in Cypress
# general-chat
w
I want to create an assertion that checks two different strings to see whether they contain a specific substring. If either of the two strings contains the substring, the assertion should be correct. How do I achieve this with Cypress? My current approach is to the following:
Copy code
javascript
   productList.each($el =>
      cy
        .wrap($el)
        .should(
          'satisfy',
          () =>
            cy.wrap($el).find('#product-title').should('contain.text', 'house blend') ||
            cy.wrap($el).find('#product-description').should('contain.text', 'house blend')
        )
    )
This seems to produce an infinite loop though. In the end, I just want this assertion to be true if either one of the strings contains the correct substring
house blend
a
You could
.get().invoke("text")
on each element and store them as variables, concatenate them together, and then verify if that resulting string contains the substring you want....
w
Thanks for the answer!
I actually just found another way, which is to select them both together as part of the
find()
statement
57 Views