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

Support "ok" in mockResponse

Open superoo7 opened this issue 5 years ago • 4 comments

Screenshot 2019-04-24 at 5 07 29 PM

from typescrpit types, MockParams does not support response properties of "ok"

It would be good to support "ok" since fetch implementation does have "ok" in the properties.

Screenshot 2019-04-24 at 5 06 37 PM

https://github.github.io/fetch/#Response

superoo7 avatar Apr 24 '19 09:04 superoo7

Hi, you cannot explicitely set it, but it works ;)

Simple example: fetchMock.mockResponseOnce(JSON.stringify({ a: 1 }), { status: 200 });

and after debugging my response, you can see, variable exists. image

And on the other hand, ok == false when I set status to 400. image

Magnielcz avatar Apr 29 '19 15:04 Magnielcz

I think what @Magnielcz makes sense. Internally jest fetch mock uses the Response object which automatically sets the ok property.

jefflau avatar May 08 '19 06:05 jefflau

Hello !

I have the same problem as @superoo7

I set the status to 400 but still get a ok: true response.

Console.log of the mocked response image

Code of the mock image

You can see that the arguments in the body and the status are the good one, however, still an ok: true.

silverspectro avatar Dec 03 '19 11:12 silverspectro

Hello !

I have the same problem as @superoo7

I set the status to 400 but still get a ok: true response.

Console.log of the mocked response image

Code of the mock image

You can see that the arguments in the body and the status are the good one, however, still an ok: true.

I'm having the same issue

EgidioCaprino avatar Jul 12 '23 13:07 EgidioCaprino