@4c/fetch-mock
Version:
Mock http requests made using fetch (or isomorphic-fetch)
54 lines (37 loc) • 2.52 kB
Markdown
# fetch-mock
Mock http requests made using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch)

[](https://github.com/wheresrhys/fetch-mock/blob/master/LICENSE)

[](https://circleci.com/gh/wheresrhys/workflows/fetch-mock)
[](https://coveralls.io/github/wheresrhys/fetch-mock)
[](https://snyk.io/test/github/wheresrhys/fetch-mock?targetFile=package.json)
```js
fetchMock.mock('http://example.com', 200);
const res = await fetch('http://example.com');
assert(res.ok);
fetchMock.restore();
```
## Table of Contents
- [Requirements](#requirements)
- [Documentation and Usage](http://www.wheresrhys.co.uk/fetch-mock/)
- [License](#license)
- [Housekeeping](#housekeping)
**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 - <a href="https://www.justgiving.com/refugee-support-europe">please consider donating</a>**
---
## Requirements
fetch-mock requires the following to run:
- [Node.js](https://nodejs.org/) 8+ for full feature operation
- [Node.js](https://nodejs.org/) 0.12+ with [limitations](http://www.wheresrhys.co.uk/fetch-mock/#usageinstallation)
- [npm](https://www.npmjs.com/package/npm) (normally comes with Node.js)
- Either of the following
- [node-fetch](https://www.npmjs.com/package/node-fetch) when testing in a nodejs
- A browser that supports the `fetch` API when testing in a browser
## Documentation and Usage
See the [project website](http://www.wheresrhys.co.uk/fetch-mock/)
## License
fetch-mock is licensed under the [MIT](https://github.com/wheresrhys/fetch-mock/blob/master/LICENSE) license.
Copyright © 2019, Rhys Evans
## Housekeeping

[](https://codeclimate.com/github/wheresrhys/fetch-mock/maintainability)