fetch-mock
Mock http requests made using fetch (or isomorphic-fetch)
Last updated 9 days ago by wheresrhys .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fetch-mock 
SYNC missed versions from official npm registry.

fetch-mock

Mock http requests made using fetch.

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

New If using jest, try the new fetch-mock-jest wrapper.

New Cheatsheet

node version licence npm downloads CircleCI Code coverage Known Vulnerabilities

fetchMock.mock('http://example.com', 200);
const res = await fetch('http://example.com');
assert(res.ok);
fetchMock.restore();

Table of Contents

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


Requirements

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

Documentation and Usage

See the project website or cheatsheet

If you're using jest as your test runner, consider using fetch-mock-jest, a lightweight, jest-friendly wrapper around fetch-mock.

License

fetch-mock is licensed under the MIT license. Copyright © 2019, Rhys Evans

Housekeeping

npm version maintainability

Current Tags

  • 9.10.3                                ...           latest (9 days ago)
  • 9.6.0-alpha.2                                ...           pre-release (2 months ago)

198 Versions

  • 9.10.3                                ...           9 days ago
  • 9.10.2                                ...           12 days ago
  • 9.10.1                                ...           a month ago
  • 9.10.0                                ...           a month ago
  • 9.9.1                                ...           a month ago
  • 9.9.0                                ...           2 months ago
  • 9.8.0                                ...           2 months ago
  • 9.7.0                                ...           2 months ago
  • 9.6.0                                ...           2 months ago
  • 9.6.0-alpha.2                                ...           2 months ago
  • 9.5.1                                ...           2 months ago
  • 9.6.0-alpha.1                                ...           2 months ago
  • 9.5.0                                ...           2 months ago
  • 9.4.0                                ...           3 months ago
  • 9.3.1                                ...           3 months ago
  • 9.3.0                                ...           3 months ago
  • 9.2.2                                ...           3 months ago
  • 9.2.1                                ...           4 months ago
  • 9.2.0                                ...           4 months ago
  • 9.1.2                                ...           4 months ago
  • 9.1.1                                ...           4 months ago
  • 9.1.0                                ...           4 months ago
  • 9.0.0                                ...           4 months ago
  • 9.0.0-beta.2                                ...           5 months ago
  • 8.3.2                                ...           5 months ago
  • 8.3.1                                ...           6 months ago
  • 8.3.0                                ...           6 months ago
  • 8.2.1                                ...           6 months ago
  • 8.2.0-beta.2                                ...           6 months ago
  • 8.2.0-beta.1                                ...           6 months ago
  • 8.1.0                                ...           7 months ago
  • 8.0.3                                ...           7 months ago
  • 8.0.1                                ...           7 months ago
  • 8.0.0                                ...           8 months ago
  • 7.7.3                                ...           8 months ago
  • 8.0.0-alpha.14                                ...           8 months ago
  • 8.0.0-alpha.13                                ...           8 months ago
  • 8.0.0-alpha.12                                ...           8 months ago
  • 7.7.2                                ...           8 months ago
  • 8.0.0-alpha.11                                ...           8 months ago
  • 8.0.0-alpha.10                                ...           8 months ago
  • 7.7.0                                ...           8 months ago
  • 7.6.0                                ...           8 months ago
  • 8.0.0-alpha.9                                ...           8 months ago
  • 8.0.0-alpha.8                                ...           8 months ago
  • 8.0.0-alpha.7                                ...           8 months ago
  • 8.0.0-alpha.6                                ...           8 months ago
  • 8.0.0-alpha.5                                ...           8 months ago
  • 8.0.0-alpha.4                                ...           8 months ago
  • 8.0.0-alpha.3                                ...           8 months ago
  • 8.0.0-alpha.2                                ...           8 months ago
  • 8.0.0-alpha.1                                ...           8 months ago
  • 7.5.1                                ...           9 months ago
  • 7.5.0                                ...           9 months ago
  • 7.4.0                                ...           9 months ago
  • 7.3.9                                ...           a year ago
  • 7.3.8                                ...           a year ago
  • 7.3.7                                ...           a year ago
  • 7.3.6                                ...           a year ago
  • 7.3.3                                ...           a year ago
  • 7.3.1                                ...           a year ago
  • 7.3.0                                ...           2 years ago
  • 7.2.8                                ...           2 years ago
  • 7.2.7                                ...           2 years ago
  • 7.2.5                                ...           2 years ago
  • 7.2.4                                ...           2 years ago
  • 7.2.3                                ...           2 years ago
  • 7.2.2                                ...           2 years ago
  • 7.2.1                                ...           2 years ago
  • 7.2.0                                ...           2 years ago
  • 7.1.0                                ...           2 years ago
  • 7.0.8                                ...           2 years ago
  • 7.0.7                                ...           2 years ago
  • 7.0.6                                ...           2 years ago
  • 7.0.5                                ...           2 years ago
  • 7.0.2                                ...           2 years ago
  • 7.0.1                                ...           2 years ago
  • 7.0.0                                ...           2 years ago
  • 7.0.0-beta.2                                ...           2 years ago
  • 7.0.0-beta.1                                ...           2 years ago
  • 7.0.0-alpha.6                                ...           2 years ago
  • 6.5.2                                ...           2 years ago
  • 6.5.1                                ...           2 years ago
  • 6.5.0                                ...           2 years ago
  • 6.4.4                                ...           2 years ago
  • 6.4.3                                ...           2 years ago
  • 6.4.2                                ...           2 years ago
  • 6.4.1                                ...           2 years ago
  • 6.4.0                                ...           2 years ago
  • 6.3.0                                ...           2 years ago
  • 6.2.0                                ...           2 years ago
  • 6.1.1                                ...           2 years ago
  • 6.1.0                                ...           2 years ago
  • 6.1.0-beta.2                                ...           2 years ago
  • 6.0.1                                ...           2 years ago
  • 6.0.0                                ...           2 years ago
  • 6.0.0-beta.10                                ...           2 years ago
  • 6.0.0-beta.9                                ...           2 years ago
  • 6.0.0-beta.7                                ...           2 years ago
  • 6.0.0-beta.6                                ...           2 years ago
  • 6.0.0-beta.5                                ...           2 years ago
  • 6.0.0-beta.4                                ...           2 years ago
  • 6.0.0-beta.3                                ...           2 years ago
  • 6.0.0-beta.2                                ...           2 years ago
  • 5.13.1                                ...           3 years ago
  • 5.13.0                                ...           3 years ago
  • 5.12.2                                ...           3 years ago
  • 5.12.1                                ...           3 years ago
  • 5.12.0                                ...           3 years ago
  • 5.11.2                                ...           3 years ago
  • 5.11.1                                ...           3 years ago
  • 5.11.0                                ...           3 years ago
  • 5.10.1                                ...           3 years ago
  • 5.10.0                                ...           3 years ago
  • 5.9.4                                ...           3 years ago
  • 5.9.3                                ...           3 years ago
  • 5.9.2                                ...           3 years ago
  • 5.9.1                                ...           3 years ago
  • 5.9.0                                ...           3 years ago
  • 5.8.1                                ...           3 years ago
  • 5.8.0                                ...           4 years ago
  • 5.7.0                                ...           4 years ago
  • 5.6.2                                ...           4 years ago
  • 5.6.1                                ...           4 years ago
  • 5.6.0                                ...           4 years ago
  • 5.5.0                                ...           4 years ago
  • 5.4.0                                ...           4 years ago
  • 5.3.1                                ...           4 years ago
  • 5.3.0                                ...           4 years ago
  • 5.2.0                                ...           4 years ago
  • 5.1.5                                ...           4 years ago
  • 5.1.4                                ...           4 years ago
  • 5.1.3                                ...           4 years ago
  • 5.1.2                                ...           4 years ago
  • 5.1.1                                ...           4 years ago
  • 5.1.0                                ...           4 years ago
  • 5.0.5                                ...           4 years ago
  • 5.0.4                                ...           4 years ago
  • 5.0.3                                ...           4 years ago
  • 5.0.2                                ...           4 years ago
  • 5.0.1                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.6.1                                ...           4 years ago
  • 4.6.0                                ...           4 years ago
  • 4.5.4                                ...           4 years ago
  • 4.5.3                                ...           4 years ago
  • 4.5.2                                ...           4 years ago
  • 4.5.1                                ...           4 years ago
  • 4.5.0                                ...           4 years ago
  • 4.4.0                                ...           4 years ago
  • 4.3.1                                ...           4 years ago
  • 4.3.0                                ...           4 years ago
  • 4.2.0                                ...           4 years ago
  • 4.1.1                                ...           4 years ago
  • 4.1.0                                ...           4 years ago
  • 4.0.1                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 3.2.1                                ...           5 years ago
  • 3.2.0                                ...           5 years ago
  • 3.1.3                                ...           5 years ago
  • 3.1.2                                ...           5 years ago
  • 3.1.1                                ...           5 years ago
  • 3.1.0                                ...           5 years ago
  • 3.0.4                                ...           5 years ago
  • 3.0.3                                ...           5 years ago
  • 3.0.2                                ...           5 years ago
  • 3.0.1                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.4.0                                ...           5 years ago
  • 2.3.1                                ...           5 years ago
  • 2.3.0                                ...           5 years ago
  • 2.2.15                                ...           5 years ago
  • 2.2.14                                ...           5 years ago
  • 2.2.13                                ...           5 years ago
  • 2.2.12                                ...           5 years ago
  • 2.2.11                                ...           5 years ago
  • 2.2.10                                ...           5 years ago
  • 2.2.9                                ...           5 years ago
  • 2.2.8                                ...           5 years ago
  • 2.2.7                                ...           5 years ago
  • 2.2.6                                ...           5 years ago
  • 2.2.3                                ...           5 years ago
  • 2.2.1                                ...           5 years ago
  • 2.2.0                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 1.5.2                                ...           5 years ago
  • 1.5.0                                ...           5 years ago
  • 1.4.1                                ...           5 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Downloads
Today 85
This Week 443
This Month 231
Last Day 65
Last Week 657
Last Month 2,966
Dependencies (9)
Dependents (134)

Copyright 2014 - 2016 © taobao.org |