cypress: cy.get fails once in a while with "expected undefined to be enabled"
After upgrading to 6.0.1
tests that weren’t flaky became flaky and I believe it’s not an issue with our code.
Current behavior

Desired behavior
If an element is not found I expect Cypress to fail as it normally does when it cannot find an element. (“Timed out retrying: Expected to find element: input[name=email], but never found it.”) And if an element is found it expect it not to fail 8)
Versions
Cypress 6.x
(6.0.0
exhibited the same issue)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 9
- Comments: 22 (2 by maintainers)
This’s comeback in Cypress 7x (I checked on
7.0.0
and7.0.1
):It marks test as flaky, because it passes the second time.
This issue still happens to me in 9.6.0.
I have a loading spinner on page, that appears and disappears as stuff loads on screen, so I wait for the spinner to appear and then disappear, and when waiting for it to disappear the ‘undefined’ problem occurs.
cy.get('.mat-progress-spinner',{timeout: 10000}).filter(':visible',{timeout: 30000}).should('have.length.at.least',1)
- workscy.get('.mat-progress-spinner',{timeout: 10000}).filter(':visible',{timeout: 30000}).should('have.length',0)
- does not work, and the cy log in test runner saysexpected undefined to have a length of 0
Interesting enough, it does NOT reach the ‘undefined’ straight away, but waits a bit before reaching the ‘undefined’ log message
Waiting for the element to be visible, working 100% correct all the time
Waiting for the element to disappear, it processes for 1-2 seconds
And then this is the result while waiting for the element to disappear
This should be resolved in Cypress 12 - see https://github.com/cypress-io/cypress/pull/24628 for the big refactor of how subjects are determined and commands chain together / retry.
Sorry it took us so long to get to this - this is pretty fundamental to how Cypress executes commands, retries things, and chains subjects together. #7306 has a ton of discussion around the subject (and around how Cy12 is going to solve it), so I’m going to refer people there and close this one, just to keep things a bit more centralized.
This has been happening intermittently for me for quite a while, always very early in my tests. Forcing a
cy.wait(10 * 1000)
after loading the webapp doesn’t help (I thought it might be related to the webapp taking too long to load).I don’t believe it’s related to
cy.intercept
- though I recently added this, it was happening long before this addition to my tests.Currently on Cypress v9.6.1.