https://cypress.io logo
I'm aware of how to create custom commands like `...
# e2e-testing
w
I'm aware of how to create custom commands like
Cypress.Commands.add('login', (username, pw) => {...})
But how do I do it when the argument needs to be an actual element? I'm wanting to do something like this that checks every matched element for the conditions (not just the first one that matches).
Copy code
Cypress.Commands.add('checkElementClass', (element, class) => {
  element.should('have.class', class);
});

...

// Check every <li> has the class
cy.get('ul>li').each((($el, index, $list)) => {
  cy.checkElementClass($el, 'myClass');
});
// or
cy.get('ul>li').eq(0).as('li0');  cy.checkElementClass(li0, 'myClass');
// etc.