Manuals / Cypress / Chapter 5

B · Core · intermediate · Week 3–4 · Chapter 5 of 12

cy.intercept — stub, spy, and wait

Network control separates junior from mid-level Cypress. Stub slow or flaky APIs, simulate errors, and assert request payloads — without leaving the browser.

Path progress
35%

Step 1 of 4

Spy on GET

cy.intercept("GET", "/inventory.json").as("getInventory"); cy.wait("@getInventory") ensures data loaded before assert.

Spy on GETDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Spy on GETdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Do this now

Add intercept + wait to inventory test. Assert 6 items render after @getInventory.

Was this step clear?
Chapter learning outcomes
  • Route matching
  • Aliases @getItems
  • Stub vs spy
  • Fixture responses

Clear these before you leave

Side quest

Slow network simulation

Use intercept delay to test loading spinner. Assert spinner visible then hidden.