Cypress: Test if element does not exist

前端 未结 7 2150
一个人的身影
一个人的身影 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:00

    Cypress 6.x Migration

    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

提交回复
热议问题