View on GitHub


Mock http requests made using fetch


fetch is assigned to a local variable, not a global

First of all, consider whether you could just use fetch as a global. Here are 3 reasons why this is a good idea:

Still not convinced?

In that case fetchMock.sandbox() can be used to generate a function which you can pass in to a mock loading library such as mockery instead of fetch

fetch doesn’t seem to be getting mocked?

Environment doesn’t support requiring fetch-mock?

Matching Request objects in node fails

In node, if using npm at a version less than 2 the Request constructor used by fetch-mock won’t necessarily be the same as the one used by node-fetch. To fix this either: