← Back to library
Cypressassertionsintermediatev10+
Assert every list item contains text
Use .each() to iterate over results and assert each one matches a condition.
1it('every search result mentions the keyword', () => {
2 cy.visit('/search?q=playwright');
3
4 cy.get('[data-testid="result-item"]')
5 .should('have.length.greaterThan', 0)
6 .each(($el) => {
7 // cy.wrap() gives you Cypress commands on the raw jQuery element
8 cy.wrap($el).should('contain.text', 'playwright');
9 });
10});#each#contain#list#loop