# fetch-mock

> Mock http requests made using fetch

Latest version **12.6.0** (published 2025-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install fetch-mock
pnpm add fetch-mock
yarn add fetch-mock
bun add fetch-mock
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 12.6.0 |
| Published | 2025-10-30 |
| First published | 2015-05-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.11.0 |
| Dependencies | 4 |
| Unpacked size | 153.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1309 |
| Author | Rhys Evans |
| Maintainers | wheresrhys |
| Keywords | fetch, http, mock, testing, spy, stub |

## Links

- npm: https://www.npmjs.com/package/fetch-mock
- Repository: https://github.com/wheresrhys/fetch-mock
- Homepage: http://www.wheresrhys.co.uk/fetch-mock
- Issues: https://github.com/wheresrhys/fetch-mock/issues
- npm.io page: https://npm.io/package/fetch-mock

## Dependencies (4)

- [dequal](https://npm.io/package/dequal.md) ^2.0.3
- [regexparam](https://npm.io/package/regexparam.md) ^3.0.0
- [glob-to-regexp](https://npm.io/package/glob-to-regexp.md) ^0.4.1
- [@types/glob-to-regexp](https://npm.io/package/@types/glob-to-regexp.md) ^0.4.4

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [@depup/casual](https://npm.io/package/@depup/casual.md) — 0 weekly downloads
- [@availity/mock-server](https://npm.io/package/@availity/mock-server.md) — 0 weekly downloads
- [@scotthuang/agent-knock-knock-pi](https://npm.io/package/@scotthuang/agent-knock-knock-pi.md) — 0 weekly downloads

## Recent versions

- 12.6.0 (latest) — 2025-10-30
- 10.0.8-alpha.1 (pre-release) — 2024-07-14
- 12.5.6 — 2025-10-29
- 12.5.5 — 2025-10-22
- 12.5.4 — 2025-08-28
- 12.5.3 — 2025-06-17
- 12.5.2 — 2025-03-03
- 12.5.1 — 2025-03-01
- 12.4.0 — 2025-02-23
- 12.3.0 — 2025-02-04
- 12.2.1 — 2025-01-28
- 12.2.0 — 2024-11-15
- 12.1.0 — 2024-11-08
- 12.0.2 — 2024-10-28
- 12.0.1 — 2024-10-27
- … 226 more at https://npm.io/package/fetch-mock/versions

## README

# fetch-mock

Features include:

- mocks most of the fetch API spec, even advanced behaviours such as streaming and aborting
- declarative matching for most aspects of a http request, including url, headers, body and query parameters
- shorthands for the most commonly used features, such as matching a http method or matching one fetch only
- support for delaying responses, or using your own async functions to define custom race conditions
- can be used as a spy to observe real network requests
- can be extended with your own reusable custom matchers that can be used both for matching fetch-calls and inspecting the results
- isomorphic, and supports either a global fetch instance or a locally required instance

## Requirements

@fetch-mock requires either of the following to run:

- [Node.js](https://nodejs.org/) 18+ for full feature operation
- Any modern browser that supports the `fetch` API
- [node-fetch](https://www.npmjs.com/package/node-fetch) when testing in earlier versions of Node.js (this is untested, but should mostly work)

## Documentation and Usage

See the [project website](https://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 © 2024, Rhys Evans

---
_Source: https://npm.io/package/fetch-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
