Skip to content

Functions react() and getReact() don't retry upcoming assertions #339

@daniele-pini

Description

@daniele-pini

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:

return resolveValue().then((value) => {
return value;
});

Removing the then() call makes the test succeed as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions