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
Current behavior
cy.waitaccepts 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:
Desired behavior
Users can currently await serially to get items in order:
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:
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