0
0
Cypresstesting~5 mins

Stubbing responses in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is stubbing responses in Cypress?
Stubbing responses means replacing real server replies with fake data during tests. It helps test how the app behaves without needing the real server.
Click to reveal answer
beginner
Why use stubbing responses in tests?
To make tests faster, reliable, and independent from real servers. It also helps test edge cases by controlling the response data.
Click to reveal answer
beginner
How do you stub a GET request in Cypress?
Use cy.intercept() with the URL and provide a fake response object. For example: cy.intercept('GET', '/api/data', { fixture: 'data.json' })
Click to reveal answer
intermediate
What is the difference between stubbing and spying in Cypress?
Stubbing changes the response to fake data. Spying only watches the request without changing it.
Click to reveal answer
intermediate
What should you consider when stubbing responses?
Make sure the stub matches the real API shape. Avoid stubbing too much to keep tests realistic. Clean up stubs after tests.
Click to reveal answer
What does cy.intercept() do in Cypress?
AIntercepts and can stub network requests
BRuns the test faster by skipping steps
CGenerates random test data
DClears browser cookies
Why stub responses instead of calling the real server?
ATo avoid testing UI
BTo test without internet connection
CTo make tests slower
DTo make tests unreliable
Which command stubs a POST request in Cypress?
Acy.intercept('POST', '/api/save', { statusCode: 200 })
Bcy.visit('/api/save')
Ccy.stub('POST', '/api/save')
Dcy.spy('POST', '/api/save')
What is a fixture in Cypress stubbing?
AA CSS style
BA browser plugin
CA test runner
DA file with fake data used to stub responses
What happens if you don’t stub a failing server response?
ATest will skip network calls
BTest will always pass
CTest may fail unpredictably
DTest will run faster
Explain how to stub a network response in Cypress and why it is useful.
Think about replacing real server replies with your own data.
You got /4 concepts.
    Describe the difference between spying and stubbing in Cypress testing.
    One observes, the other replaces.
    You got /3 concepts.