Cypress · Middle · Question 26 of 77

What is the difference between cy.spy and cy.stub?

Show the answer

Correct answer: A spy records calls and keeps the original; a stub replaces it

Explanation

Use a spy to check an analytics call happened, a stub to prevent a side effect or force a return value.

Further reading

Problem with a question

Cypress · Middle · question 26

Test yourself

Take the Cypress · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz