Previously I had Jest code to test for the value of a non-secure cookie. It looked like this:
expect(Cookie.get('myToken')).toBe('tokenvalue');
(the Cookie
in this instance is using the js-cookie
api)
However, I tried to update how I set my cookie, and added the secure
flag and set it to true
. Jest no longer can see this cookie when the test runs.
What's the best way to test it?
I've looked at questions like Jest secure cookies?
I've also tested the code and checked in a browser that the secure flag is set. So this is just a testing issue. My code to set the cookie looks like this:
Cookie.set('myToken', values.user.token, {
path: '/',
expires: new Date(new Date().getTime() + TOKEN_DURATION),
secure: true
});