Skip to content

Chains of query commands do not retry anything before an assertion #25134

Open
@bahmutov

Description

Current behavior

Notice in v12 (using 12.1.0 right now) that if there are assertions in the chain of queries, the query commands before an assertion are NOT retried, even if the assertion should pass.

Desired behavior

Cypress should go all the way to the start of the chain of queries and retry it, even if there are assertions in the mix.

Test code to reproduce

const double = (n) => n * 2

// @ts-ignore
Cypress.Commands.addQuery('apply', (fn) => (n) => fn(n))

it('fails to retry the cy.its', () => {
  const list = []
  cy.wrap(list)
    .its(0) // first item
    // this assertion breaks the query chain retries
    // it never "sees" the new number 5
    // because it never retries cy.its above
    .should('be.a', 'number')
    .apply(double)
    .should('equal', 10)

  setTimeout(() => {
    list[0] = 1
  }, 1000)

  setTimeout(() => {
    list[0] = 5
  }, 2000)
})

it('retries queries with assertions', () => {
  const list = []
  cy.wrap(list)
    // several queries (without assertion)
    .its(0) // first item
    .apply(double)
    .should('equal', 10)

  setTimeout(() => {
    list[0] = 1
  }, 1000)

  setTimeout(() => {
    list[0] = 5
  }, 2000)
})

Screen Shot 2022-12-13 at 12 39 45

https://github.com/bahmutov/cypress-map/blob/main/cypress/e2e/chain-with-assertions.cy.js

Cypress Version

v12

Node version

16

Operating System

mac

Debug Logs

No response

Other

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    prevent-stalemark an issue so it is ignored by stale[bot]stage: ready for workThe issue is reproducible and in scopetype: unexpected behaviorUser expected result, but got another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions