Cypress offers a simple way to test for server-side redirects using request:
cy.request({
url: `/dashboard/`,
followRedirect: false, // turn off following redirects
}).then((resp) => {
expect(resp.redirectedToUrl).to.eq('http://example.com/session/new')
})
However this doesn't work for client-side redirects because the page is loaded successfully before the redirect happens, meaning the response is for the page, not for the redirect.
How can I test a client-side redirect?
I need a way of catching the redirect and verifying that:
- it occurred
- was to the correct URL.
I don't want to follow the redirect away from the app that is being tested.
Aucun commentaire:
Enregistrer un commentaire