Skip to main content

Network Stubbing & Intercepts

cy.intercept() lets you observe, modify, or mock any network request the browser makes. This is one of Cypress's most powerful features — you can test loading states, error handling, and edge cases without needing a real backend.

Watching a Request

Ctrl+Enter
HTML
CSS
JS
Preview

cy.wait('@alias') gives you the actual request and response objects for assertions.

Stubbing a Response

Ctrl+Enter
HTML
CSS
JS
Preview

The real API never gets called — Cypress returns your fixture immediately.

Testing Error States

Ctrl+Enter
HTML
CSS
JS
Preview

Without stubbing, reproducing error states requires a real failing API.

Network Intercept Visualiser

Request intercept simulation
Ctrl+Enter
HTML
CSS
JS
Preview

Dynamic Route Matching

Ctrl+Enter
HTML
CSS
JS
Preview

Using Fixtures

Ctrl+Enter
HTML
CSS
JS
Preview
cy.intercept('GET', '/api/products', { fixture: 'products.json' }).as('getProducts')

Fixtures keep test data out of test files and make it easy to share across tests.