jest-fetch-mock icon indicating copy to clipboard operation
jest-fetch-mock copied to clipboard

How to mock with cookies?

Open Bessonov opened this issue 6 years ago • 2 comments

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?

Bessonov avatar Apr 16 '19 20:04 Bessonov

I am having the same issue

Have you managed to solve it?

hacknlove avatar Sep 30 '21 11:09 hacknlove

This is working for me

        fetchMock.mockResponse(() => Promise.resolve({
            body: JSON.stringify({ ok: true }),
            headers: [
                ['set-cookie', 'some cookie'],
                ['set-cookie', 'more cookies']
            ]                
        }));

hacknlove avatar Sep 30 '21 11:09 hacknlove