Cypress commands do not all treat callbacks in the same way. A callback passed to then runs only once when the preceding command
resolves. If an assertion in that callback observes an intermediate state, it fails immediately even when the application would reach the expected
state shortly afterward.
In contrast, Cypress retries a callback passed to should together with the preceding query until its assertions pass or the timeout
expires. Assertions on asynchronous user-interface state should therefore use should so they benefit from Cypress retryability and do not
make tests intermittently fail.
This rule targets then callbacks that only make assertions, optionally using local calculations. Keep then when the
callback performs one-time side effects or transforms the yielded value, because retrying or replacing those operations could change the test’s
behavior.
cy.get("[data-cy=status]").then(($status) => { // Noncompliant: assertions in "then" are not retried
expect($status.text()).to.equal("Ready");
});
Replace then with should when the callback only computes values and asserts on them.
cy.get("[data-cy=status]").should(($status) => {
expect($status.text()).to.equal("Ready");
});
thenshould