Angular › End to End Testing with Cypress & Playwright

How would you mock a backend API response during an end to end test to avoid depending on a real server?

Advanced

Answer

Both Cypress and Playwright let you intercept outgoing network requests and respond with fake data instead of letting the request actually reach a real server, making tests faster, more reliable, and independent of any backend actually being available or in a specific state.
// Cypress intercepting a network request
cy.intercept('GET', '/api/products', { fixture: 'products.json' }).as('getProducts');
cy.visit('/products');
cy.wait('@getProducts');
cy.contains('Product Name').should('be.visible');
Real-world example A team's end to end test suite mocks every backend API call using fixture files containing realistic sample data, letting their tests run reliably and quickly in a CI pipeline without needing a real backend server running at all.

Common follow-ups: What is the risk of relying entirely on mocked responses instead of occasionally testing against a real backend?;How do you keep fixture files in sync with the real API's actual response shape over time?