Q2 of 48 · Cypress
Explain Cypress retry-ability in your own words.
Short answer
Short answer: Most Cypress commands and assertions automatically re-run for a few seconds until they pass or time out, so you rarely need explicit waits. The chain retries the last query plus its assertions until the whole expression is satisfied.
Detail
Cypress builds retry-ability into the command queue. When you write cy.get('.cart').should('contain', 'Apples'), Cypress re-queries .cart and re-checks the assertion repeatedly until either both pass or the default 4-second timeout expires. You don't manually poll, sleep, or write waitFor helpers.
The subtle rule is which part of the chain retries. Only the last query command plus its trailing assertions retry. If you put a non-retryable command (.click(), .then(...)) into the chain, retry-ability stops at that point. That's why you'll see guidance like "don't put assertions inside .then callbacks" — once you enter .then, you've left the retrying context, and a stale element reference will fail instead of being re-queried.
Retry-ability is also why Cypress deliberately doesn't expose element.text() as a plain string. Returning a string would freeze the value and defeat the retry; instead you write cy.get('.cart').should('have.text', 'Apples') so the assertion is part of the retried chain.
Practical implications: prefer chained .should over manual .then(el => expect(el.text()).to.eq(...)), never cy.wait(2000) without a reason, and treat .then and .click as fences that stop the retry from sliding further back.
// EXAMPLE
retry.cy.ts
// ✅ Retries: .get(...) is re-queried until .should passes or times out
cy.get('[data-test=cart]').should('contain.text', 'Apples');
// ❌ Doesn't retry: .then freezes the subject. If the DOM updates
// after this snapshot, the assertion fails.
cy.get('[data-test=cart]').then(($el) => {
expect($el.text()).to.contain('Apples');
});
// ✅ Multiple chained assertions all retry together
cy.get('[data-test=cart-row]')
.should('have.length', 3)
.and('contain.text', 'Apples');