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 2.0.1 to 2.1.0

2

package.json

@@ -1,1 +0,1 @@

{"name":"fetch-mock","version":"2.0.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.1.0","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"}}

@@ -61,2 +61,14 @@ 'use strict';

var method = route.method;
var matchMethod;
if(method) {
method = method.toLowerCase();
matchMethod = function(options) {
var m = options && options.method ? options.method.toLowerCase() : 'get';
return m === method;
};
} else {
matchMethod = function(){ return true; };
}
debug('compiling route: ' + route.name);

@@ -81,9 +93,9 @@

expectedUrl = expectedUrl.substr(1);
route.matcher = function (url) {
return url.indexOf(expectedUrl) === 0;
route.matcher = function (url, options) {
return matchMethod(options) && url.indexOf(expectedUrl) === 0;
};
} else {
debug('constructing string matcher for route: ' + route.name);
route.matcher = function (url) {
return url === expectedUrl;
route.matcher = function (url, options) {
return matchMethod(options) && url === expectedUrl;
};

@@ -94,4 +106,4 @@ }

const urlRX = route.matcher;
route.matcher = function (url) {
return urlRX.test(url);
route.matcher = function (url, options) {
return matchMethod(options) && urlRX.test(url);
};

@@ -98,0 +110,0 @@ }

@@ -255,2 +255,28 @@ 'use strict';

it('match method', function(done) {
fetchMock.mock({
routes: [{
name: 'route1',
method: 'get',
matcher: 'http://it.at.here',
response: 'ok'
}, {
name: 'route2',
method: 'put',
matcher: 'http://it.at.here',
response: 'ok'
}]
});
Promise.all([fetch('http://it.at.here', {method: 'put'}), fetch('http://it.at.here'), fetch('http://it.at.here', {method: 'GET'}), fetch('http://it.at.here', {method: 'delete'})])
.then(function (res) {
expect(fetchMock.called()).to.be.true;
expect(fetchMock.called('route1')).to.be.true;
expect(fetchMock.called('route2')).to.be.true;
expect(fetchMock.calls('route1').length).to.equal(2);
expect(fetchMock.calls('route2').length).to.equal(1);
expect(fetchMock.calls('__unmatched').length).to.equal(1);
done();
}).catch(done);
});
it('match multiple routes', function (done) {

@@ -257,0 +283,0 @@ fetchMock.mock({

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