question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implicit should 'exist' assertion is not being applied on cy.get() when other assertion.

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
fvanwijkcommented, Jan 31, 2017

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.

1reaction
jennifer-shehanecommented, Apr 8, 2020

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')
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is the .should('exist') assertion redundant on Cypress?
For your usecase of asserting whether an element exists, they are indeed redundant. .contains() yields a DOM element and according to ...
Read more >
Assertions | Cypress Documentation
Watch the short video "Multiple elements and should('be.visible') assertion" that shows how to correctly check the visibility of elements. Existence. // retry ...
Read more >
What are Cypress Assertions and How to use ... - Tools QA
Assertions are the validation steps that determine whether the specified step of the automated test case succeeded or not.
Read more >
Assertions | Cypress examples (v9.7.0) - Gleb Bahmutov
In most cases, you do not need to explicitly check if the element exists - if the cy.get , cy.contains , etc. command...
Read more >
Cypress - Assertions - Tutorialspoint
If an assertion is applicable to the object obtained from the parent command in a chain, it is known as the implicit assertion....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found