cypress: cy.wait() does not resolve aliases in Cypress 6.0.x

Current behavior

After upgrading from the latest version of v5 to v6.0.0, we are seeing issues with cy.wait() not resolving aliases set with cy.intercept(). When our app makes the request, Cypress shows that the request matched and the count # under routes shows 1. See screenshot. Additionally when the route is hit, hovering over where the request occurred in the runner shows “<route> ResponseReceived aliased as: pinReport”. The subsequent cy.wait() command however times out after the default timeout saying that request never occurred.

Temporarily switching back to cy.route() also results in the same issue.

Important to mention also is that this happens about 50% of the time. Sometimes cy.wait() knows the request happened and the test passes, other times it times out like in the screenshot below.

image

Desired behavior

cy.wait() should resolve the alias when matched by cy.intercept()

Test code to reproduce

  it('should pin a report', () => {
    cy.intercept({
      method: 'POST',
      path: '/api/report_for_report_indices/*/star',
    }).as('pinReport');

    cy.getByTestId('button__pin')
      .first()
      .click({
        force: true
      });

    cy.wait('@pinReport')
      .its('response.statusCode')
      .should('eq', 204);
  });

Versions

Cypress version v6.0.0 and v6.0.1 Worked with Cypress v5.x Browser: Chrome Version 87.0.4280.67 (Official Build) (x86_64) Operating System: macOS, also ran reproducible in GitHub Actions on a ubuntu-18 container

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 21 (7 by maintainers)

Most upvoted comments

Well, something with the url is definetaly changed. (cypress 6.0.1 and cypress 6.1.0)

wait for this alias fails, but worked before (with route)

    cy.intercept({
      method: 'GET',
      url: '/Admin/api/setOffGetData?item_id=*',
    }).as('setOffGetData')

this works:

    cy.intercept({
      method: 'GET',
      url: '**/Admin/api/setOffGetData?item_id=*',
    }).as('setOffGetData')

But the cypress log shows:

image

Something is prepended to the url, but it is not visible anywhere. I hope this helps someone.

url now matches the full url, including the base path (hostname). For your first example, you would use path instead which excludes the hostname.

Well, something with the url is definetaly changed. (cypress 6.0.1 and cypress 6.1.0)

wait for this alias fails, but worked before (with route)

    cy.intercept({
      method: 'GET',
      url: '/Admin/api/setOffGetData?item_id=*',
    }).as('setOffGetData')

this works:

    cy.intercept({
      method: 'GET',
      url: '**/Admin/api/setOffGetData?item_id=*',
    }).as('setOffGetData')

But the cypress log shows:

image

Something is prepended to the url, but it is not visible anywhere. I hope this helps someone.

I believe this is related to the minimatch issue reported in other issues (such as https://github.com/cypress-io/cypress/issues/9340). Essentially .intercept is not matching glob patterns through strings.