Wait for XHR Responses in a Cypress Test

InstructorAndy Van Slaars

Share this video with your friends

Send Tweet

When testing interactions that require asynchronous calls, we’ll need to wait on responses to make sure we’re asserting about the application state at the right time. With Cypress, we don’t have to use arbitrary time periods to wait. In this lesson, we’ll see how to use an alias for a network request and wait for it to complete without having to wait longer than required or guess at the duration.

Ben
~ 6 years ago

at 0:49 Just to confirm -- it is NOT testing the XHR request to the real API, it is just delaying the stubbed request interception of that call?

Andy Van Slaarsinstructor
~ 6 years ago

Correct, but that wait behavior will work in an e2e test where there is a real delay in server response.