cypress: Individual requests aliases not working

Current behavior

When passing a callback function as the third parameter of cy.intercept() to dynamically alias individual requests they do not get aliased at all and cypress is unable to wait for them to complete.

Desired behavior

Individual requests should be able to be aliased so cypress can wait for them to complete.

Test code to reproduce

cy.visit('https://reactjs.org/');

cy.intercept('GET', '**/*', (req) => {
  req.alias = 'sampleRequest';
});

cy.wait('@sampleRequest');

Cypress Version

11.0.1

Node version

16.14.2

Operating System

macOS 10.15.7

Debug Logs

No response

Other

Cypress is able to see that the request got intercepted but on the task runner it shows requests as “No alias”.

If I manually set the alias with .as('sampleRequest') it does work correctly.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 8
  • Comments: 20 (4 by maintainers)

Most upvoted comments

This is still a problem. The aliasing works correctly and allows responses to be stubbed and requests to be waited on, however ‘no alias’ is displayed for all instances where the alias is set on the request (using request.alias = "example") inside cy.intercept`.

This is true even when intercepts are defined well before any cy.visit.

@tarrball Yeah, but I think the problem is that we want to conditionally add an alias.

@jennifer-shehane @lmiller1990 @flotwig - This bug may not be high priority in terms of functionality but the alias details not showing up in command log is creating lot of confusion, especially to track if the intercept is matched (or) not

Our app uses Mqtt and requests polled as a backup for every <n> seconds… With this issue, it is not easy to check if an appropriate fixture is sent for an intercepted request (or) not. We have to click the no alias and view the details in dev tools to confirm

Is there a timeline to fix this issue? It not, it would be great if this can be looked at in near future

@felipeptcho makes sense. I was trying to conditionally set it, but couldn’t get it to work (and then found this thread). Using as() and a little rearranging of the test made the conditional alias unnecessary (for my needs).

Hi everyone, I’m facing the same problem and from what I’ve seen it seems that the req object lacks the alias field even after hardcoding it

Captura de pantalla 2023-03-27 a las 15 39 39