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

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

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 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