What if your tests never had to wait for a slow or broken server again?
Why Stubbing responses in Cypress? - Purpose & Use Cases
Imagine testing a web app that fetches data from a server. You have to wait for the server to respond every time you test. Sometimes the server is slow or down, so you can't test properly.
Manually waiting for real server responses is slow and frustrating. Tests can fail just because the server is unavailable, not because the app is broken. This makes testing unreliable and wastes time.
Stubbing responses lets you fake the server replies. You tell your test what data to expect without calling the real server. This makes tests fast, stable, and predictable.
cy.visit('/page'); cy.wait(5000); // waiting for real server response
cy.intercept('GET', '/api/data', { fixture: 'data.json' }); cy.visit('/page');
Stubbing responses enables fast, reliable tests that work even when the real server is slow or offline.
When testing a shopping site, you can stub the product list response to always show the same items. This way, your tests won't break if the real product database changes or is down.
Manual testing with real servers is slow and unreliable.
Stubbing responses fakes server data for fast, stable tests.
This helps catch real app bugs without external delays.