I ran into a weird behaviour when running Cypress tests. It seems like cy.visit() fails to send cookies with the request.
First of all, yes, in cypress/supports/index.js I have set:
Cypress.Cookies.defaults({
preserve: 'token'
})
And in my test I do the following:
it('test', () => {
cy.logIn()
cy.getCookie('token').then(console.log)
cy.visit('/')
// verify that the user is redirected to /home, which it isn't...
})
To log the user in, I run my custom logIn() command, which successfully logs the user in. Upon doing so, the application sets a cookie named token with the session token. Then I console.log the cookie successfully just before calling cy.visit(). However, my backend receives a request with no cookies and therefore does not perform a redirect as expected...
Has anyone run into something similar? Any ideas what may be happening?