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 screen shot 2016-08-30 at 3 04 42 pm

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 18 (12 by maintainers)

Commits related to this issue

Most upvoted comments

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 regular should('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.

it('testing', () => {
  cy.get('input').should('not.be.checked')
})

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:

cy.visit('/')
  .get('#signup').should('not.exist')

the assertion fails and prints: expected #signup to exist in the DOM

it look like a bug as the .get function still tries to assert exist version: 0.19.2