fetch-mock
Advanced tools
Comparing version 3.1.3 to 3.2.0
@@ -414,3 +414,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.fetchMock = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
this.restore(); | ||
this.mock.apply(this, [].slice.apply(arguments)); | ||
return this.mock.apply(this, [].slice.apply(arguments)); | ||
} | ||
@@ -417,0 +417,0 @@ }, { |
@@ -399,3 +399,3 @@ 'use strict'; | ||
this.restore(); | ||
this.mock.apply(this, [].slice.apply(arguments)); | ||
return this.mock.apply(this, [].slice.apply(arguments)); | ||
} | ||
@@ -402,0 +402,0 @@ }, { |
{ | ||
"name": "fetch-mock", | ||
"version": "3.1.3", | ||
"version": "3.2.0", | ||
"description": "Mock http requests made using fetch (or isomorphic-fetch)", | ||
@@ -5,0 +5,0 @@ "main": "src/server.js", |
@@ -17,3 +17,3 @@ # fetch-mock [![Build Status](https://travis-ci.org/wheresrhys/fetch-mock.svg?branch=master)](https://travis-ci.org/wheresrhys/fetch-mock) | ||
#### `mock(matcher, response)` or `mock(matcher, method, response)` | ||
Replaces `fetch()` with a stub which records it's calls, grouped by route, and optionally returns a mocked `Response` object or passes the call through to `fetch()`. Calls to `.mock()` can be chained. | ||
Replaces `fetch()` with a stub which records its calls, grouped by route, and optionally returns a mocked `Response` object or passes the call through to `fetch()`. Calls to `.mock()` can be chained. | ||
@@ -35,11 +35,2 @@ * `matcher` [required]: Condition for selecting which requests to mock Accepts any of the following | ||
##### Example | ||
``` | ||
const fetchMock = require('fetch-mock'); | ||
fetchMock | ||
.mock('http://domain1', 200) | ||
.mock('http://domain2', 'DELETE', 204); | ||
``` | ||
#### `restore()` | ||
@@ -60,2 +51,21 @@ Restores `fetch()` to its unstubbed state and clears all data recorded for its calls | ||
##### Example | ||
``` | ||
fetchMock | ||
.mock('http://domain1', 200) | ||
.mock('http://domain2', 'PUT', { | ||
affectedRecords: 1 | ||
}); | ||
myModule.onlyCallDomain2() | ||
.then(() => { | ||
expect(fetchMock.called('http://domain2')).to.be.true; | ||
expect(fetchMock.called('http://domain1')).to.be.false; | ||
expect(fetchMock.calls().unmatched().length).to.equal(0); | ||
expect(JSON.parse(fetchMock.calls('http://domain2'[)[0][1].body)).to.deep.equal({prop: 'val'}); | ||
fetchMock.restore(); | ||
}) | ||
``` | ||
## Advanced usage | ||
@@ -62,0 +72,0 @@ |
@@ -370,3 +370,3 @@ 'use strict'; | ||
this.restore(); | ||
this.mock.apply(this, [].slice.apply(arguments)); | ||
return this.mock.apply(this, [].slice.apply(arguments)); | ||
} | ||
@@ -373,0 +373,0 @@ |
@@ -73,5 +73,6 @@ 'use strict'; | ||
it('have remocking helper', function () { | ||
fetchMock.mock('^http://route1', 200) | ||
fetchMock.mock('^http://route1', 200); | ||
let fm; | ||
expect(function () { | ||
fetchMock.reMock('^http://route2', 200) | ||
fm = fetchMock.reMock('^http://route2', 200) | ||
}).not.to.throw(); | ||
@@ -82,2 +83,3 @@ fetch('http://route1.com') | ||
expect(fetchMock.calls().matched[0][0]).to.equal('http://route2.com'); | ||
expect(fm).to.equal(fetchMock); | ||
}); | ||
@@ -84,0 +86,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78122
2091
293