fetch-mock
Advanced tools
Comparing version 2.2.1 to 2.2.3
@@ -1,1 +0,1 @@ | ||
{"name":"fetch-mock","version":"2.2.1","description":"Mock http requests made using fetch (or isomorphic-fetch)","main":"server.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"https://github.com/wheresrhys/fetch-mock.git"},"keywords":["fetch","http","mock","testing","spy"],"author":"Rhys Evans","license":"ISC","bugs":{"url":"https://github.com/wheresrhys/fetch-mock/issues"},"homepage":"https://github.com/wheresrhys/fetch-mock","dependencies":{"node-fetch":"^1.2.0","debug":"^2.2.0"},"devDependencies":{"babelify":"^6.3.0","browserify":"^10.0.0","chai":"^2.3.0","coveralls":"^2.11.2","debowerify":"^1.2.1","es6-promise":"^2.1.1","karma":"^0.12.31","karma-browserify":"^4.1.2","karma-chai":"^0.1.0","karma-chrome-launcher":"^0.1.8","karma-mocha":"^0.1.10","mocha":"^2.2.4","mocha-lcov-reporter":"0.0.2","npm-prepublish":"^1.2.0","sinon":"^1.17.0"}} | ||
{"name":"fetch-mock","version":"2.2.3","description":"Mock http requests made using fetch (or isomorphic-fetch)","main":"server.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"https://github.com/wheresrhys/fetch-mock.git"},"keywords":["fetch","http","mock","testing","spy"],"author":"Rhys Evans","license":"ISC","bugs":{"url":"https://github.com/wheresrhys/fetch-mock/issues"},"homepage":"https://github.com/wheresrhys/fetch-mock","dependencies":{"node-fetch":"^1.2.0","debug":"^2.2.0"},"devDependencies":{"babelify":"^6.3.0","browserify":"^10.0.0","chai":"^2.3.0","coveralls":"^2.11.2","debowerify":"^1.2.1","es6-promise":"^2.1.1","karma":"^0.12.31","karma-browserify":"^4.1.2","karma-chai":"^0.1.0","karma-chrome-launcher":"^0.1.8","karma-mocha":"^0.1.10","mocha":"^2.2.4","mocha-lcov-reporter":"0.0.2","npm-prepublish":"^1.2.0","sinon":"^1.17.0"}} |
@@ -41,3 +41,3 @@ # 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) | ||
The following are also accepted by mock() and translated into `config` objects with the `routes` property defined using the values passed in to mock as follows: | ||
* `mock(name, matcher, response)` - configuration for a single named route to be mocked | ||
* `mock(matcher, method, response)` - configuration for a single unnamed route to be mocked for a given method. To access details of its calls `fetchMock.calls()` should be called without passing a parameter | ||
* `mock(matcher, response)` - configuration for a single unnamed route to be mocked. To access details of its calls `fetchMock.calls()` should be called without passing a parameter | ||
@@ -51,6 +51,7 @@ * `mock(route)` - configuration object for a single route | ||
* `name`: A unique string naming the route | ||
* `method`: If specified will only match requests using the given http method | ||
* `matcher`: The rule for matching calls to `fetch()`. Accepts any of the following | ||
* `string`: Either an exact url to match e.g. 'http://www.site.com/page.html' or, if the string begins with a `^`, the string following the `^` must begin the url e.g. '^http://www.site.com' would match 'http://www.site.com' or 'http://www.site.com/page.html' | ||
* `RegExp`: A regular expression to test the url against | ||
* `Function(url, opts)`: A function that is passed the url and opts `fetch()` is called with and that returns a Boolean | ||
* `Function(url, opts)`: A function that is passed the url and opts `fetch()` is called with and that returns a Boolean. | ||
* `response`: Configures the response object returned by the mock. Can take any of the following values | ||
@@ -57,0 +58,0 @@ * `number`: creates a response with the number as the response status |
@@ -247,3 +247,3 @@ 'use strict'; | ||
mock (name, matcher, response) { | ||
mock (matcher, method, response) { | ||
@@ -255,4 +255,5 @@ let config; | ||
routes: [{ | ||
name, | ||
name: '_mock', | ||
matcher, | ||
method, | ||
response | ||
@@ -262,21 +263,21 @@ }] | ||
} else if (matcher) { | ||
} else if (method) { | ||
config = { | ||
routes: [{ | ||
name: '_mock', | ||
matcher: name, | ||
response: matcher | ||
matcher, | ||
response: method | ||
}] | ||
} | ||
} else if (name instanceof Array) { | ||
} else if (matcher instanceof Array) { | ||
config = { | ||
routes: name | ||
routes: matcher | ||
} | ||
} else if (name && name.matcher) { | ||
} else if (matcher && matcher.matcher) { | ||
config = { | ||
routes: [name] | ||
routes: [matcher] | ||
} | ||
} else { | ||
config = name; | ||
config = matcher; | ||
} | ||
@@ -283,0 +284,0 @@ |
@@ -122,8 +122,8 @@ 'use strict'; | ||
describe('shorthand notation', function () { | ||
it('accepts name, matcher, route triples', function () { | ||
it('accepts matcher, method, route triples', function () { | ||
expect(function () { | ||
fetchMock.mock('route', 'http://it.at.there', 'ok'); | ||
fetchMock.mock('http://it.at.there', 'PUT', 'ok'); | ||
}).not.to.throw(); | ||
fetch('http://it.at.there'); | ||
expect(fetchMock.calls('route').length).to.equal(1); | ||
fetch('http://it.at.there', {method: 'PUT'}); | ||
expect(fetchMock.calls().length).to.equal(1); | ||
}); | ||
@@ -139,2 +139,10 @@ | ||
it('accepts single route', function () { | ||
expect(function () { | ||
fetchMock.mock({name: 'route', matcher: 'http://it.at.there', response: 'ok'}); | ||
}).not.to.throw(); | ||
fetch('http://it.at.there'); | ||
expect(fetchMock.calls('route').length).to.equal(1); | ||
}); | ||
it('accepts array of routes', function () { | ||
@@ -141,0 +149,0 @@ expect(function () { |
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
47907
1161
264
63