My test results in adding a row to the table. In afterEach hook I wanted to add a method to delete the newest row after the test ran so I wrote this piece of code:
deleteTheNewestRequest() {
cy.get('table#return-request-list').find('tr').eq(1).then( firstRow => {
cy.wrap(firstRow).find('td').eq(0).invoke('text').as('rowId')
cy.wrap(firstRow).find('a[title="Delete"]').click()
cy.get('button.btn-delete-return-request').click()
cy.wrap(firstRow).find('td').first().should('not.have.text', this.rowId)
})
}
With 'then' I'm saving a table element to later use to find and operate on the elements inside it. I wanted to first save the value of the newest row in the table that was added after the test ran successfully, then delete and as the last step make sure that the row with the ID that was deleted is actually gone from the table. The problem is that cypress test runner assertions marks it green because it sees that value of is not equal to 'undefined' and not, let's say 3794.