fetch-mock: Mocked fetch does not support a call with Request as one argument
Mocked fetch does not support a call with Request as one argument:
fetch(new Request(...))
Produces errors like request.url.headers are undefined.
I have to call it like this in my code so far:
var req = new Request(...);
fetch(req.url, req)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 21 (7 by maintainers)
I agree, but I’ve asked before in this thread for somebody to provide a reduced test case. Also pull requests are welcome. Why not turn your temporary solution into a permanent solution for everyone 😄
I have this problem as well.
fetchnormally supports invoking it with a single argument of typeRequest(according to this documentation).But from the very definition of the mocked
fetchimplementation provided by this library here, it becomes evident that the mockedfetchalways expectfetchto be called asfetch(url, options). No where in that method it is considered the possibility thaturlis not a string, or thatoptionscould be missing. In fact, the only thing done aroundoptionbeing missing is defaulting to methodGET. I actually realized all this whenfetch-mockwas giving me an error that there was no fallback response for aGETrequest, in an example where I was only firing a singlePOSTrequest. The only caveat is that in my app, the requests are built as aRequestobject, which is then passed tofetch.