fetch-mock

WebJar for fetch-mock

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

fetch-mock
Last Version

Last Version

5.9.4
Release Date

Release Date

Type

Type

jar
Description

Description

fetch-mock
WebJar for fetch-mock
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/wheresrhys/fetch-mock

Download fetch-mock

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/fetch-mock/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>fetch-mock</artifactId>
    <version>5.9.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/fetch-mock/
implementation 'org.webjars.npm:fetch-mock:5.9.4'
// https://jarcasting.com/artifacts/org.webjars.npm/fetch-mock/
implementation ("org.webjars.npm:fetch-mock:5.9.4")
'org.webjars.npm:fetch-mock:jar:5.9.4'
<dependency org="org.webjars.npm" name="fetch-mock" rev="5.9.4">
  <artifact name="fetch-mock" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='fetch-mock', version='5.9.4')
)
libraryDependencies += "org.webjars.npm" % "fetch-mock" % "5.9.4"
[org.webjars.npm/fetch-mock "5.9.4"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.npm : glob-to-regexp jar [0.3.0,0.4)
org.webjars.npm : node-fetch jar [1.3.3,2)
org.webjars.npm : path-to-regexp jar [1.7.0,2)

Project Modules

There are no modules declared in this project.

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

Versions

Version
5.9.4