← Back to library
Cypressnetworkintermediatev10+
Intercept and modify a response body
Intercept a real API response and overwrite specific fields before they reach the app.
1it('shows an overdue badge when API returns an overdue status', () => {
2 cy.intercept('GET', '/api/tasks', (req) => {
3 req.reply((res) => {
4 // Mutate a single field in the real response — everything else stays
5 res.body.tasks[0].status = 'overdue';
6 });
7 }).as('getTasks');
8
9 cy.visit('/tasks');
10 cy.wait('@getTasks');
11
12 // The app should render the overdue badge based on the patched status
13 cy.get('[data-testid="task-0"] [data-testid="status-badge"]')
14 .should('have.text', 'Overdue');
15});#intercept#modify#response#body#req.reply