I am trying to check if element doesn't exist in a DOM Tree with Cypress and testing-library/cypress.
If I try to do cy.getByTestId("my-button").should("not.exist")
test fails because it couldn't find element.
If I do cy.findByTestId("my-button").should("not.exist")
it also fails because of time out.
The test does work if I do either cy.queryByTestId("my-button").should("not.exist")
or
cy.get('[data-testid="my-button"]').should("not.exist")
.
Can someone please explain what's the difference between all 4.
Thanks
cy.findByTestId(...)
with.should("not.exist")
– ShearinfindBy
andgetBy
return error if element isn't found that's why cannot be used for my test.queryBy
returns null and doesn't fail the test. But what doescy.get('[data-testid="my-button"]')
return when element is not in a DOM? – Burck