Reputation: 5801
I have a use-case when the first .my-class
should be in one state, and all the rest siblings .my-class
should be in another, so I need to make a few assertions on the first and a few others on the rest.
Here is my first access:
cy.get('.custom-expand').first().should('have.class', 'custom-expand-expanded')
How can I assert the rest should('not.have.class'
?
Upvotes: 2
Views: 1859
Reputation: 5801
You can access the rest elements by the nextAll
function:
cy.get('.cx-custom-expand').first().should('have.class', 'cx-custom-expand-expanded')
cy.get('.cx-custom-expand').first().nextAll().should('not.have.class', 'cx-custom-expand-expanded')
Or even:
const first = cy.get('.cx-custom-expand').first()
const rest = first.nextAll()
// do you tests on them
first.should('have.class', 'cx-custom-expand-expanded')
rest.should('not.have.class', 'cx-custom-expand-expanded')
Upvotes: 4