UNPKG

2.52 kBMarkdownView Raw
1# fetch-mock
2
3Mock http requests made using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch)
4
5![node version](https://img.shields.io/node/v/fetch-mock.svg?style=flat-square)
6[![licence](https://img.shields.io/npm/l/fetch-mock.svg?style=flat-square)](https://github.com/wheresrhys/fetch-mock/blob/master/LICENSE)
7![npm downloads](https://img.shields.io/npm/dm/fetch-mock.svg?style=flat-square)
8[![CircleCI](https://img.shields.io/circleci/project/github/wheresrhys/fetch-mock.svg?style=flat-square)](https://circleci.com/gh/wheresrhys/workflows/fetch-mock)
9[![Code coverage](https://img.shields.io/coveralls/github/wheresrhys/fetch-mock.svg?style=flat-square)](https://coveralls.io/github/wheresrhys/fetch-mock)
10[![Known Vulnerabilities](https://snyk.io/test/github/wheresrhys/fetch-mock/badge.svg?targetFile=package.json&style=flat-square)](https://snyk.io/test/github/wheresrhys/fetch-mock?targetFile=package.json)
11
12```js
13fetchMock.mock('http://example.com', 200);
14const res = await fetch('http://example.com');
15assert(res.ok);
16fetchMock.restore();
17```
18
19## Table of Contents
20
21- [Requirements](#requirements)
22- [Documentation and Usage](http://www.wheresrhys.co.uk/fetch-mock/)
23- [License](#license)
24- [Housekeeping](#housekeping)
25
26**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>**
27
28---
29
30## Requirements
31
32fetch-mock requires the following to run:
33
34- [Node.js](https://nodejs.org/) 8+ for full feature operation
35- [Node.js](https://nodejs.org/) 0.12+ with [limitations](http://www.wheresrhys.co.uk/fetch-mock/#usageinstallation)
36- [npm](https://www.npmjs.com/package/npm) (normally comes with Node.js)
37- Either of the following
38 - [node-fetch](https://www.npmjs.com/package/node-fetch) when testing in a nodejs
39 - A browser that supports the `fetch` API when testing in a browser
40
41## Documentation and Usage
42
43See the [project website](http://www.wheresrhys.co.uk/fetch-mock/)
44
45## License
46
47fetch-mock is licensed under the [MIT](https://github.com/wheresrhys/fetch-mock/blob/master/LICENSE) license.
48Copyright © 2018, Rhys Evans
49
50## Housekeeping
51
52![npm version](https://img.shields.io/npm/v/fetch-mock.svg?style=flat-square)
53[![maintainability](https://api.codeclimate.com/v1/badges/7f8abbf54ec9f3d07df3/maintainability?style=flat-square)](https://codeclimate.com/github/wheresrhys/fetch-mock/maintainability)