Cypress: Test if element does not exist
Use .should('not.exist')
to assert that an element does not exist in the DOM.
Do not use not.visible
assertion. It would falsely pass in < 6.0, but properly fail now:
// for element that was removed from the DOM
// assertions below pass in < 6.0, but properly fail in 6.0+
.should('not.be.visible')
.should('not.contain', 'Text')
Migration Docs here: Migrating-to-Cypress-6-0
Well this seems to work, so it tells me I have some more to learn about .should()
cy.get('.check-box-sub-text').should('not.exist');
you can also search a for a text which is not supposed to exist:
cy.contains('[email protected]').should('not.exist')
Here you have the result in Cypress: 0 matched elements
documentation: https://docs.cypress.io/guides/references/assertions.html#Existence