← Back to library
Cypresswaitintermediatev10+
Wait for a network response
Use cy.intercept + cy.wait to pause until an API call completes before asserting.
1it('waits for API before asserting', () => {
2 // Set up the intercept BEFORE the action that triggers it
3 cy.intercept('GET', '/api/items').as('getItems');
4
5 cy.visit('/items');
6
7 // Wait for the aliased request to complete
8 cy.wait('@getItems').then(({ response }) => {
9 expect(response.statusCode).to.eq(200);
10 expect(response.body).to.have.length.greaterThan(0);
11 });
12
13 cy.contains('Item list loaded').should('be.visible');
14});#wait#intercept#alias#network