Socket
Socket
Sign inDemoInstall

fetch-mock

Package Overview
Dependencies
Maintainers
1
Versions
226
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-mock - npm Package Compare versions

Comparing version 3.0.2 to 3.0.3

Licence

2

package.json
{
"name": "fetch-mock",
"version": "3.0.2",
"version": "3.0.3",
"description": "Mock http requests made using fetch (or isomorphic-fetch)",

@@ -5,0 +5,0 @@ "main": "src/server.js",

@@ -1,12 +0,9 @@

# fetch-mock [![Build Status](https://travis-ci.org/wheresrhys/fetch-mock.svg?branch=master)](https://travis-ci.org/wheresrhys/fetch-mock) [![Coverage Status](https://coveralls.io/repos/wheresrhys/fetch-mock/badge.svg)](https://coveralls.io/r/wheresrhys/fetch-mock)
# fetch-mock [![Build Status](https://travis-ci.org/wheresrhys/fetch-mock.svg?branch=master)](https://travis-ci.org/wheresrhys/fetch-mock)
Mock http requests made using fetch (or [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch)). As well as shorthand methods for the simplest use cases, it offers a flexible API for customising mocking behaviour, and can also be persisted (with resettable state) over a series of tests.
- [V3 changelog](https://github.com/wheresrhys/fetch-mock/pull/35)
## Installation and usage
## Which file to require
- Browser or nodejs 4 or higher `require('fetch-mock')`
- Browser tests when not using a loader that respects the `browser` field of package.json: `require('fetch-mock/es5/client')`
- Server side tests running in nodejs 0.12 or lower: `require('fetch-mock/es5/server')`
`npm install fetch-mock` then `require('fetch-mock')` in most environments
You will need to ensure `fetch` and `Promise` are already available as globals in your environment
[Troubleshooting](#troubleshooting) [V3 changelog](https://github.com/wheresrhys/fetch-mock/pull/35)

@@ -79,3 +76,3 @@ *To output useful messages for debugging `export DEBUG=fetch-mock`*

```javascript
```
responses: {

@@ -120,3 +117,3 @@ session: function (url, opts) {

##### Mockery example
```javascript
```
var fetch = require('node-fetch');

@@ -138,2 +135,13 @@ var fetchMock = require('fetch-mock');

## Troubleshooting
### Environment doesn't support requiring fetch-mock?
- If your client-side code or tests do not use a loader that respects the browser field of package.json use `require('fetch-mock/es5/client')`. This can also be loaded directly in a script tag as `./node_modules/fetch-mock/es5/client.js` (Disclaimer: I haven't actually tried this, but it should work)
- For server side tests running in nodejs 0.12 or lower use `require('fetch-mock/es5/server')`
### Polyfilling fetch
- In nodejs `require('isomorphic-fetch')` before any of your tests.
- In the browser `require('isomorphic-fetch')` can also be used, but it may be easier to `npm install whatwg-fetch` (the module isomorphic-fetch is built around) and load `./node_modules/whatwg-fetch/fetch.js` directly into the page, either in a script tag or by referencing it your test runner config
## Examples

@@ -140,0 +148,0 @@ ```javascript

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc