fetch-mock
Advanced tools
Comparing version 7.3.9 to 7.4.0
@@ -27,2 +27,4 @@ 'use strict'; | ||
var isEqual = require('lodash.isequal'); | ||
var stringMatchers = { | ||
@@ -127,2 +129,25 @@ begin: function begin(targetString) { | ||
var getBodyMatcher = function getBodyMatcher(_ref9) { | ||
var expectedBody = _ref9.body; | ||
return function (url, _ref10) { | ||
var body = _ref10.body, | ||
_ref10$method = _ref10.method, | ||
method = _ref10$method === undefined ? 'get' : _ref10$method; | ||
if (method.toLowerCase() === 'get') { | ||
// GET requests don’t send a body so the body matcher should be ignored for them | ||
return true; | ||
} | ||
var sentBody = void 0; | ||
try { | ||
sentBody = JSON.parse(body); | ||
} catch (_) {} | ||
return sentBody && isEqual(sentBody, expectedBody); | ||
}; | ||
}; | ||
var getUrlMatcher = function getUrlMatcher(route) { | ||
@@ -176,3 +201,3 @@ var matcher = route.matcher, | ||
module.exports = function (route) { | ||
var matchers = [route.query && getQueryStringMatcher(route), route.method && getMethodMatcher(route), route.headers && getHeaderMatcher(route), route.params && getParamsMatcher(route), getFunctionMatcher(route), getUrlMatcher(route)].filter(function (matcher) { | ||
var matchers = [route.query && getQueryStringMatcher(route), route.method && getMethodMatcher(route), route.headers && getHeaderMatcher(route), route.params && getParamsMatcher(route), route.body && getBodyMatcher(route), getFunctionMatcher(route), getUrlMatcher(route)].filter(function (matcher) { | ||
return !!matcher; | ||
@@ -179,0 +204,0 @@ }); |
{ | ||
"name": "fetch-mock", | ||
"version": "7.3.9", | ||
"version": "7.4.0", | ||
"description": "Mock http requests made using fetch (or isomorphic-fetch)", | ||
@@ -53,2 +53,3 @@ "main": "src/server.js", | ||
"glob-to-regexp": "^0.4.0", | ||
"lodash.isequal": "^4.5.0", | ||
"path-to-regexp": "^2.2.1", | ||
@@ -55,0 +56,0 @@ "whatwg-url": "^6.5.0" |
@@ -24,3 +24,3 @@ # fetch-mock | ||
- [License](#license) | ||
- [Housekeeping](#housekeping) | ||
- [Housekeeping](#housekeeping) | ||
@@ -27,0 +27,0 @@ **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 - <a href="https://www.justgiving.com/refugee-support-europe">please consider donating</a>** |
@@ -10,2 +10,3 @@ const glob = require('glob-to-regexp'); | ||
} = require('./request-utils'); | ||
const isEqual = require('lodash.isequal'); | ||
@@ -76,2 +77,19 @@ const stringMatchers = { | ||
const getBodyMatcher = ({ body: expectedBody }) => { | ||
return (url, { body, method = 'get' }) => { | ||
if (method.toLowerCase() === 'get') { | ||
// GET requests don’t send a body so the body matcher should be ignored for them | ||
return true; | ||
} | ||
let sentBody; | ||
try { | ||
sentBody = JSON.parse(body); | ||
} catch (_) {} | ||
return sentBody && isEqual(sentBody, expectedBody); | ||
}; | ||
}; | ||
const getUrlMatcher = route => { | ||
@@ -122,2 +140,3 @@ const { matcher, query } = route; | ||
route.params && getParamsMatcher(route), | ||
route.body && getBodyMatcher(route), | ||
getFunctionMatcher(route), | ||
@@ -124,0 +143,0 @@ getUrlMatcher(route) |
Sorry, the diff of this file is too big to display
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
1446299
9486
6
+ Addedlodash.isequal@^4.5.0
+ Addedlodash.isequal@4.5.0(transitive)