Skip to content
masterclass Buddy

Cypress · Function

cy.stub

cy.stub() replaces a function with a Sinon stub. It records calls and lets you control the function's behavior, such as its return value or thrown error.

Last updated

Since
0.18.8

Syntax

cy.stub()
cy.stub(object, method)

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • .as()
  • cy.clock()
  • cy.spy()
  • Stubs, spies, and clocks

Source: cy.stub() | Cypress API Documentation. Checked 2026-11-03.