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

192
Visualizações
Is there a better way to assert that all intercepted requests are successful in Cypress?

I'm trying to test that all 12 requests involved in creating an object are successful, so far this is the only way I can figure out that works. IS there a better/more efficient/more flexible way that won't break as soon as we add or remove a request?

              cy.intercept('/api/**/**').as('objectCreation');
              $button.click();

              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
              cy.wait('@objectCreation').its('response.statusCode').should('eq', 200);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'll like more details about your question:

  • Are the requests identical?

However, to answer your question on how to simplify your shared, code snippet...you could create a variable representing the request creation attempts & keep calling the cy.intercept() method & asserting its response until you hit the specified request creation amount like so:

const reqObjCreationNum = 0; // reqObjCreationNum object creation attempts number

/**
 * @param {number} reqObjCreationNum - number of object creation attempts
 */
const createObject = ({ reqObjCreationNum }) => {
  cy.intercept('/api/**/**').as('objectCreation');

  while (reqObjCreationNum <= 12) {
    cy.wait('@objectCreation')
      .its('response.statusCode')
      .should('eq', 200);

    reqObjCreationNum += 1;
  }
};

createObject({ reqObjCreationNum });

I would suggest the DRY programming concept as a future reading.

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