lecture 3 of 150 completed

Faking the server's answer

Stubbing lets you test hard situations like server errors. It is powerful, and it has a cost you must know.

What you'll learn

  • How to test states you cannot easily create
  • What stubbing costs you in real coverage
  • Which paths must never be stubbed

This builds on cy.intercept, so it is also something you run on a local project rather than in the editor here. The technique is standard on real Cypress teams, and interviewers ask about its trade-off often.

Your product manager asks a fair question: "What does the app show when the server is down?"

You want to test it. But how? You cannot break the real server just to run a test.

You can make Cypress answer the request for you. This is called stubbing: your test gives a fake answer instead of letting the request reach the real server.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →