I want to be able to click on a check box and test that an element is no longer in the DOM in Cypress. Can someone suggest how you do it?
//This is the Test
you can also search a for a text which is not supposed to exist:
cy.contains('test_invite_member@gmail.com').should('not.exist')
Here you have the result in Cypress: 0 matched elements
documentation: https://docs.cypress.io/guides/references/assertions.html#Existence
You can also use below code
expect(opportunitynametext.include("Addon")).to.be.false
or
should('be.not.be.visible')
or
should('have.attr','minlength','2')
cy.get('[data-e2e="create-entity-field-relation-contact-name"]').should('not.exist');
might lead to some false results, as some error messages get hidden. It might be better to use
.should('not.visible');
in that case.
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: https://docs.cypress.io/guides/references/migration-guide.html#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');
Here's what worked for me:
cy.get('[data-cy=parent]').should('not.have.descendants', 'img')
I check that some <div data-cy="parent">
has no images inside.
Regarding original question, you can set data-cy="something, i.e. child"
attribute on inner nodes and use this assertion:
cy.get('[data-cy=parent]').should('not.have.descendants', '[data-cy=child]')