Complete the code to intercept a GET request to '/api/data'.
cy.[1]('GET', '/api/data').as('getData')
The cy.intercept() command is used to intercept HTTP requests in Cypress. Here, it intercepts a GET request to '/api/data'.
Complete the code to stub the response with a status code 200 and body { success: true }.
cy.intercept('GET', '/api/data', [1]).as('getData')
To stub a response, you provide an object with statusCode and body. Here, status 200 and a success body are correct.
Fix the error in the code to wait for the intercepted request alias 'getData'.
cy.[1]('@getData')
The cy.wait() command waits for the intercepted request to complete using its alias.
Fill both blanks to intercept a POST request to '/api/login' and stub a 401 unauthorized response.
cy.intercept('[1]', '/api/login', [2]).as('loginAttempt')
The first blank is the HTTP method 'POST'. The second blank is the stub response with status 401 for unauthorized.
Fill all three blanks to intercept a PUT request to '/api/user/123', stub a response with status 204, and wait for it.
cy.intercept('[1]', '/api/user/123', [2]).as('[3]') cy.wait('@userUpdate')
The HTTP method is PUT for updating. The stub response uses status 204 (no content). The alias is 'userUpdate' which is used in cy.wait().