Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cy.wait on an array of the same alias does not resolve in expected order #27337

Closed
mike-plummer opened this issue Jul 19, 2023 · 1 comment · Fixed by #27806
Closed

cy.wait on an array of the same alias does not resolve in expected order #27337

mike-plummer opened this issue Jul 19, 2023 · 1 comment · Fixed by #27806
Assignees
Labels
E2E Issue related to end-to-end testing Reproducible Can be reproduced Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.

Comments

@mike-plummer
Copy link
Contributor

mike-plummer commented Jul 19, 2023

Current behavior

cy.wait accepts an array of aliases to await - this behavior works as expected when different aliases as supplied (cy.wait(['@a', '@b'])), however when the same alias is supplied multiple times the resolved subjects are not ordered from first-to-last as one would expect.

For example:

cy.intercept('url').as('@req')

//...multiple calls are made to the intercepted endpoint...

cy.wait(['@req', '@req', '@req']).then((subjects) => {
    // I would expect `subjects` to be in order of incidence (first intercepted request, second, third...)
    // order of `subjects` appears to be arbitrary
	// subjects[0] does not always correspond to the first interception
	// ditto with subjects[1], [2], etc
})

Desired behavior

Users can currently await serially to get items in order:

cy.wait('@req').then((req) => ...do your assertions on the first interception...)
cy.wait('@req').then((req) => ...do your assertions on the second interception...)
cy.wait('@req').then((req) => ...do your assertions on the third interception...)

but this prevents easy comparison of multiple awaited subjects. One workaround that been identified is to wait serially and combine into an array, but this relies on variables and state outside of the Cypress command chain which has inherent risks:

const waitedRequests = []
for (let i = 0; i < 3; i++) {
  cy.wait('@req').then((req) => {
    waitedRequests.push(req)
  })
}

cy.then(() => {
 // `waitedRequests` should contain all three requests in order here
})

Test code to reproduce

https://github.com/mike-plummer/cypress-wait-alias-array

Cypress Version

12.15.0

Node version

16.17.1

Operating System

macOS 13.4.1

Debug Logs

No response

Other

Based off of cypress-io/cypress-support-internal/issues/13

@mike-plummer mike-plummer added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. Reproducible Can be reproduced labels Jul 19, 2023
@astone123 astone123 self-assigned this Sep 12, 2023
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 11, 2023

Released in 13.3.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.3.1, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
E2E Issue related to end-to-end testing Reproducible Can be reproduced Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants