Functions react() and getReact() don't retry upcoming assertions
daniele-pini opened this issue · comments
Summary
I can't make functions react
and getReact
wait for chained should()
statements to complete successfully. To illustrate, try adding the following test to file cypress/integration/calculator.spec.js
in this repo:
it('getReact should retry upcoming assertions', () => {
const assertFn = cy.stub().returns(false);
assertFn.onCall(5).returns(true);
cy.getReact('t').should(() => {
// should retry 10 times
const value = assertFn();
expect(value).to.equal(true); // this should ultimately succeed at the 5th retry
});
});
This test currently fails, but it should actually work fine.
Why is this happening?
Cypress seems to consider a chain of "upcoming assertions" to be broken by any chained command that is not an assertion, which makes sense. Here are the relevent lines in Cypress.
I think then then()
call added at the end of react
and getReact
is breaking the user's chain of assertions:
cypress-react-selector/src/reactHandler.js
Lines 276 to 278 in dd00c52
Removing the then()
call makes the test succeed as expected.