Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Cypress doesn't like to share the value with multiple aliases

In my beforeEach I have

cy.intercept('GET', '**/api/v2/invoices**').as('getPaidInvoices');

I have some tests where I use getPaidInvoices with exactle same path. But then I have different test

cy.intercept('GET', '**/api/v2/invoices**').as('getInvoices');
cy.wait('@getInvoices').then((xhr) => {
expect(xhr.response.statusCode).to.equal(200);

Then I have cy with each loop for options in drop-down menu. By clicking on each option inside, I await request different for each option. The address is almost the same, except the last two ** will get different arguments.

The problem seems Cypress doesn't like to share the value of getPaidInvoices with GetInvoices. On the line with

cy.intercept('GET', '**/api/v2/invoices**').as('getInvoices');

it says "This request matched: cy.intercept() spy with alias @getPaidInvoices

Is there any workaround? I need "/api/v2/invoices" to be used my multiple aliases. Or is there option to do it without aliases?

Thank you

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This part 'GET', '**/api/v2/invoices**' is the "routeMatcher". When two intercepts use the same routeMatcher, the last one defined is supposed to be the one that handles the call.

However, from your description, it seems to be the other way round.

There's a couple of ways to handle it, the best IMO is to use a function and assign the alias within it

From Aliasing individual requests

cy.intercept('GET', '**/api/v2/invoices**', (req) => {

  // test the url string
  if (req.url.includes('paid')) {  // check the arguments
    req.alias = 'getPaidInvoices'
  } else {
    req.alias = 'getInvoices'
  }
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!