cypress: Implicit should 'exist' assertion is not being applied on cy.get() when other assertion.
Using cy.get() on an element should implicitly assert existence of the element. But in my examples below, you can see that I have no element foobarbaz, the Command Log correctly logs 0 elements found, yet my explicitly written assertions (not.be.visible and not.have.class) chained off of the gotten element pass.
cy.get() should always implicitly assert existence unless there is an explicit assertion down the chain on that element asserting that it should not.exist.
Example Test Code
it("dom element doesn't have attributes", function() {
cy.get("foobarbaz").should("not.be.visible");
cy.get("foobarbaz").should("not.have.class", "foo");
});
Example Command Log

About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 18 (12 by maintainers)
Commits related to this issue
- add Happo visual tests for a component test (#205) — committed to cypress-io/cypress by bahmutov 4 years ago
I like to have
cy.get('@someAlias').should('not.exist')to have the same behavior, because according to the docs an alias requeries the element.Currently for a non-existing selection my example returns
Timed out retrying: Expected to find element: ’someAlias', but never found it., while a regularshould('not.exist')passes.Another use case from #6958 - notice I’m not even visiting a website and this passes because the checkbox doesn’t event exist.
Hey @Bkucera, I think you may have linked the wrong PR above in your comment. Did you mean this? https://github.com/cypress-io/cypress/pull/3268
I’m getting some weird behavior with this, when trying this assertion:
the assertion fails and prints:
expected #signup to exist in the DOMit look like a bug as the
.getfunction still tries to assertexistversion: 0.19.2