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

@alias.all Throws An Error When Defining Alias in Intercept With Route Handler in Version 12 #25448

Closed
blabute opened this issue Jan 12, 2023 · 12 comments · Fixed by #28352
Closed
Labels
topic: alias Issues with alias creation or use type: bug

Comments

@blabute
Copy link

blabute commented Jan 12, 2023

Current behavior

Currently, if you use cy.intercept with a route handler to define the alias, grabbing all instances of the alias @alias.all throws an error. This worked before upgrading to version 12 (verified it works with 11.2.0).

There error is:

cy.get() could not find a registered alias for: @alias.
You have not aliased anything yet.

Desired behavior

Regardless of if you define an alias using .as or request.alias, you should still be able to access all of the alias instances using @alias.all.

Test code to reproduce

I grabbed https://github.com/cypress-io/cypress/blob/develop/packages/driver/cypress/e2e/commands/net_stubbing.cy.ts#L3678-L3691 and changed the way we alias the request to expose the issue.

let routeCount = 0
const uniqueRoute = (route) => {
  routeCount += 1

  return `${route}-${routeCount}`
}

it('gets all aliased Interceptions by alias.all', function () {
    const url = uniqueRoute('/foo')

    cy.intercept(`${url}*`, (request) => {
      request.alias = 'alias';
      request.reply({ bar: 'baz' });
    })
      .then(() => {
        Cypress.$.get(url)
        Cypress.$.get(url)
      })
      .wait('@alias').wait('@alias')

      cy.get('@alias.all').then((interceptions) => {
        expect(interceptions).to.have.length(2)
      })
  })

Cypress Version

12.*

Node version

v16.19.0

Operating System

Debian GNU/Linux 11 (bullseye)

Debug Logs

No response

Other

I was following #24653 and #25210 which seem to be related but not exactly the same. Since one issue was closed, I decided to raise this issue which shows a specific example that was working before upgrading to version 12.

@chrisbreiding
Copy link
Contributor

Is it documented somewhere that setting request.alias = 'alias' should work? As far as I know, the only supported method for aliasing a request is with .as().

@blabute
Copy link
Author

blabute commented Jan 17, 2023

Is it documented somewhere that setting request.alias = 'alias' should work? As far as I know, the only supported method for aliasing a request is with .as().

Yup! Here is a guide to working with graphql which happens to be our use case.

With the test I linked in the issue, cy.wait('@alias') works without error (which seems like the alias is getting created). It's only when accessing cy.get('@alias.all') that the issue happens.

@chrisbreiding
Copy link
Contributor

TIL! Definitely not working as documented then. I'll route this to my team to investigate.

@chrisbreiding chrisbreiding removed their assignment Jan 17, 2023
@chrisbreiding chrisbreiding added type: bug topic: alias Issues with alias creation or use labels Jan 17, 2023
@fznsakib
Copy link

I'm getting the same issue when trying to access the last instance of the alias (@alias.last) even though the alias does come up in the list of available aliases

@blabute
Copy link
Author

blabute commented Feb 13, 2023

Good day!
Any updates on this issue?

@blabute
Copy link
Author

blabute commented Apr 3, 2023

Hello @chrisbreiding!

Can we please have a status update on this issue?

@ittaibaratz
Copy link

Also seeing this issue with 12.14.0

@jnunez95
Copy link

jnunez95 commented Jun 23, 2023

Also seeing this issue with 12.15.0, have same problem before reported?

@y88huang
Copy link

Same issue with 12.17.4

@adsl88788190-QwQ
Copy link

adsl88788190-QwQ commented Sep 5, 2023

Same issue with v13.1.0 😢

@arto80
Copy link

arto80 commented Oct 18, 2023

Same issue with v13.2.0

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 21, 2023

Released in 13.6.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Nov 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: alias Issues with alias creation or use type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants