Consider this Cypress test code that stubs a GET request to '/api/user' and returns a fixed user object. What will be the value of response.body.name inside the test?
cy.intercept('GET', '/api/user', { statusCode: 200, body: { name: 'Alice', age: 30 } }).as('getUser') cy.visit('/profile') cy.wait('@getUser').then(({ response }) => { const userName = response.body.name cy.wrap(userName).as('userName') }) cy.get('@userName').should('equal', 'Alice')
Look at the stubbed response body in the cy.intercept call.
The stubbed response returns a body with { name: 'Alice', age: 30 }. So response.body.name is "Alice".
You stub a POST request to '/api/login' with status code 201. Which assertion correctly checks this status code in Cypress?
cy.intercept('POST', '/api/login', { statusCode: 201, body: { token: 'abc123' } }).as('login') cy.visit('/login') cy.get('button').click() cy.wait('@login').then(({ response }) => { // Which assertion goes here? })
Check the exact property name for status code in the response object.
The correct property for HTTP status code in Cypress response is statusCode. Others are invalid or undefined.
Look at this Cypress code snippet. The test expects to stub a GET request to '/api/data', but the stub never triggers. What is the likely cause?
cy.intercept('GET', '/api/data', { fixture: 'data.json' }).as('getData') cy.visit('/dashboard') cy.wait('@getData')
Check if the request URL matches exactly the stub URL.
If the real request URL has query parameters like '/api/data?page=1', the stub for '/api/data' won't match unless you use a pattern or wildcard.
Why do testers stub network responses in end-to-end tests?
Think about how stubbing affects test speed and reliability.
Stubbing isolates frontend tests from backend changes, reduces flakiness, and speeds up tests by avoiding real network calls.
You want to stub a GET request to '/api/items' and delay the response by 2 seconds to simulate slow network. Which command achieves this?
Check the exact property name Cypress uses to delay stubbed responses.
Cypress uses delayMs to delay stubbed responses in milliseconds. Other properties are invalid.