Cypress · Middle · Question 9 of 77
How do you simulate a network failure for a request?
- 1
cy.intercept('/api/data', { forceNetworkError: true }) - 2
cy.request('/api/data').fail() - 3
cy.intercept('/api/data', { statusCode: 0 })
Show the answer
Correct answer: cy.intercept('/api/data', { forceNetworkError: true })
Explanation
It makes the request fail as if the connection dropped, so you can check offline or retry handling.