Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda