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?
AdvancedAnswer
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.