jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
883 stars 116 forks source link

Support "ok" in mockResponse #119

Open superoo7 opened 5 years ago

superoo7 commented 5 years ago

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

Magnielcz commented 5 years ago

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

jefflau commented 5 years ago

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

silverspectro commented 4 years ago

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.

EgidioCaprino commented 1 year ago

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