Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda