-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support buffers when mocking responses #223
base: master
Are you sure you want to change the base?
Conversation
mock fetch manually using cross-fetch.Response and change it to jest-fetch-mock if/when jefflau/jest-fetch-mock#223 lands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, it looks like responseWrapper
in src/index.js
needs to be modified. That function creates a Response
object via the constant ActualResponse
that holds the JavaScript Response
class. As the constructor for that class doesn't accept another Response
object, the types of body
and response
in responseWrapper
need to be checked to determine if that's already a Response
object.
thanks @andreasg123! Co-authored-by: Andreas Girgensohn <andreasg123@users.noreply.github.com>
@andreasg123 Took another shot at it. What do you thnk? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this wasn't the correct place to check for Response
after all. I believe that this change in normalizeResponse
should do it:
return resp instanceof ActualResponse
? resp
: typeof resp === 'string'
? responseWrapper(resp, init)
: responseWrapper(resp.body, responseInit(resp, init))
@andreasg123 Unfortunately if we swap out the check to go in fetchMock.mockResponse(new Response('foo')) I am perhaps missing something and welcome your continued feedback. Sorry if I wasn't able to grasp what you were talking about on the first try! |
@alexkolson, I'm concerned about these cases: fetchMock.mockResponse(request => new Response('foo'));
fetchMock.mockResponse(request => Promise.resolve(new Response('foo'))); I don't think that those would work without the change that I suggested. For those examples, |
As |
👋 @yinzara
This would add support for the issue referenced in #218. This would be really useful for me and perhaps others as well! Let me know if this looks okay and/or if I should implement in a different way. Thanks!