Mock http requests made using fetch
fetchMock.mock('http://example.com', 200);
const res = await fetch('http://example.com');
assert(res.ok);
fetchMock.restore();
I devote a lot of time to maintaining fetch-mock for free. I don't ask for payment, but am raising money for a refugee charity - please consider donating
fetch-mock requires the following to run:
- Node.js 8+ for full feature operation
- Node.js 0.12+ with limitations
- npm (normally comes with Node.js)
- Either of the following
- node-fetch when testing in a nodejs
- A browser that supports the
fetch
API when testing in a browser
See the project website
fetch-mock is licensed under the MIT license.
Copyright © 2018, Rhys Evans