In Cypress, how do you correctly test an application flow that involves a redirect after a form submission?

React JS interview question for Advanced practice.

Answer

Intercept the form submission API call, wait for its response, and then assert that a unique element on the destination page is visible.

Explanation

Option C is the most robust and reliable strategy. Asserting the URL immediately (A) is a race condition. Using a fixed wait (B) is an anti-pattern that is both slow and unreliable. The correct approach is to wait for the events that precede the redirect (like the form submission API call completing) and then confirm the outcome by waiting for a unique piece of content on the new page to appear. This deterministically confirms the redirect was successful.

Related Questions