Reputation: 465
I'm testing multiple delete from a table, but to ensure that not all items are deleted by mistake I want to leave the first item. The selector is the same for every row, but I need to filter the selection after fetching. This code deletes all items, works but how do I test with 1 remaining?
cy.get('[data-cy="item"]').click({multiple: true })
cy.contains('button', 'Delete selected').click()
Upvotes: 1
Views: 148
Reputation: 31954
You can slice the selected elements
cy.get('[data-cy="item"]')
.invoke('slice', 1) // exclude 1st row
.click({multiple: true})
cy.contains('button', 'Delete selected').click()
cy.get('[data-cy="item"]')
.its('length')
.should('eq', 1)
Upvotes: 2