My goal is to test pagination by clicking on the Next button until it becomes disabled. Despite the code I used below, the Next button continues to be clicked even after it has the disabled class, resulting in an error being thrown by Cypress.
static pagination(){
var index = 0
cy.get('li [data-test="page-link"]:not(.active):not([aria-label="Next"]) :not([aria-label="Previous"]').as("pages")
cy.get('@pages').its('length').then( len =>{
if(index <= len){
cy.get('[data-test="page-link"][aria-label="Next"]').then( next=>{
cy.wrap(next).invoke('hasClass', 'disabled').then( classDisable =>{
if(classDisable==false){
cy.wait(500)
cy.wrap(next).should('not.have.class', 'disabled')
cy.wrap(next).click()
}
this.pagination()
index++
})
})
}
})
}