fix(cy.intercept): always wait for request before waiting for response (#16457)

This commit is contained in:
Zach Bloomquist
2021-05-11 15:31:43 -04:00
committed by GitHub
parent 82f0b0c941
commit 157e363a2d
2 changed files with 12 additions and 1 deletions
@@ -2899,6 +2899,18 @@ describe('network stubbing', { retries: { runMode: 2, openMode: 0 } }, function
.wait('@getUsers')
})
// @see https://github.com/cypress-io/cypress/issues/16451
it('yields the expected interception when two requests are raced', function () {
cy.intercept('/foo*', { times: 1 }, { delay: 100, body: 'bar' }).as('a')
cy.intercept('/foo*', { times: 1 }, 'foo').as('a')
cy.then(() => {
$.get('/foo')
$.get('/foo')
})
.wait('@a').its('response.body').should('eq', 'foo')
.wait('@a').its('response.body').should('eq', 'bar')
})
// @see https://github.com/cypress-io/cypress/issues/9306
context('cy.get(alias)', function () {
it('gets the latest Interception by alias', function () {
@@ -40,7 +40,6 @@ export function waitForRoute (alias: string, state: Cypress.State, specifier: 'r
const request = requests[i]
if (RESPONSE_WAITED_STATES.includes(request.state)) {
request.requestWaited = true
request.responseWaited = true
return request