jest-fetch-mock
jest-fetch-mock copied to clipboard
How to mock with cookies?
Thank you for this great library!
I want to test a scenario, where a higher order utility function get in second request a :cookie: . To set headers seems not be handled by jest-fetch-mock:
fetchMock.mockResponseOnce(
'body',
{
status: 200,
headers: {
'set-cookie': 'my=cookie; Path=/;'
}
}
)
If I use react-cookie, then I can set the cookie, but for all requests, not second one.
Is there any way to workaround without touch the higher order utility function?
I am having the same issue
Have you managed to solve it?
This is working for me
fetchMock.mockResponse(() => Promise.resolve({
body: JSON.stringify({ ok: true }),
headers: [
['set-cookie', 'some cookie'],
['set-cookie', 'more cookies']
]
}));