Cypress: Test if element does not exist

前端 未结 7 2177
一个人的身影
一个人的身影 2020-12-09 14:42

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          


        
7条回答
  •  余生分开走
    2020-12-09 15:06

    Here's what worked for me:

    cy.get('[data-cy=parent]').should('not.have.descendants', 'img')
    

    I check that some

    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]')
    

提交回复
热议问题