fetch-mock
Advanced tools
Comparing version 3.0.3 to 3.0.4
@@ -7,2 +7,3 @@ 'use strict'; | ||
theGlobal: window, | ||
Request: window.Request, | ||
Response: window.Response, | ||
@@ -9,0 +10,0 @@ Headers: window.Headers, |
@@ -10,2 +10,3 @@ 'use strict'; | ||
var Headers = undefined; | ||
var Request = undefined; | ||
var Response = undefined; | ||
@@ -66,2 +67,12 @@ var stream = undefined; | ||
function toRequest(url, options) { | ||
var request; | ||
if (Request.prototype.isPrototypeOf(url)) { | ||
request = url; | ||
} else { | ||
request = new Request(url, options); | ||
} | ||
return request; | ||
} | ||
function compileRoute(route) { | ||
@@ -73,4 +84,4 @@ | ||
method = method.toLowerCase(); | ||
matchMethod = function (options) { | ||
var m = options && options.method ? options.method.toLowerCase() : 'get'; | ||
matchMethod = function (req) { | ||
var m = req && req.method ? req.method.toLowerCase() : 'get'; | ||
return m === method; | ||
@@ -106,3 +117,4 @@ }; | ||
route.matcher = function (url, options) { | ||
return matchMethod(options) && url.indexOf(expectedUrl) === 0; | ||
var req = toRequest(url, options); | ||
return matchMethod(req) && req.url.indexOf(expectedUrl) === 0; | ||
}; | ||
@@ -112,3 +124,4 @@ } else { | ||
route.matcher = function (url, options) { | ||
return matchMethod(options) && url === expectedUrl; | ||
var req = toRequest(url, options); | ||
return matchMethod(req) && req.url === expectedUrl; | ||
}; | ||
@@ -122,3 +135,4 @@ } | ||
route.matcher = function (url, options) { | ||
return matchMethod(options) && urlRX.test(url); | ||
var req = toRequest(url, options); | ||
return matchMethod(req) && urlRX.test(req.url); | ||
}; | ||
@@ -135,2 +149,3 @@ })(); | ||
Headers = opts.Headers; | ||
Request = opts.Request; | ||
Response = opts.Response; | ||
@@ -137,0 +152,0 @@ stream = opts.stream; |
'use strict'; | ||
var Request = require('node-fetch').Request; | ||
var Response = require('node-fetch').Response; | ||
@@ -10,2 +11,3 @@ var Headers = require('node-fetch').Headers; | ||
theGlobal: GLOBAL, | ||
Request: Request, | ||
Response: Response, | ||
@@ -12,0 +14,0 @@ Headers: Headers, |
{ | ||
"name": "fetch-mock", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Mock http requests made using fetch (or isomorphic-fetch)", | ||
@@ -5,0 +5,0 @@ "main": "src/server.js", |
@@ -22,3 +22,3 @@ # fetch-mock [![Build Status](https://travis-ci.org/wheresrhys/fetch-mock.svg?branch=master)](https://travis-ci.org/wheresrhys/fetch-mock) | ||
* `RegExp`: A regular expression to test the url against | ||
* `Function(url, opts)`: A function (returning a Boolean) that is passed the url and opts `fetch()` is called with. | ||
* `Function(url, opts)`: A function (returning a Boolean) that is passed the url and opts `fetch()` is called with (or, if `fetch()` was called with one, the `Request` instance) | ||
* `method` [optional]: only matches requests using this http method | ||
@@ -25,0 +25,0 @@ * `response` [required]: Configures the http response returned by the mock. Can take any of the following values |
@@ -7,2 +7,3 @@ 'use strict'; | ||
theGlobal: window, | ||
Request: window.Request, | ||
Response: window.Response, | ||
@@ -9,0 +10,0 @@ Headers: window.Headers, |
'use strict'; | ||
let Headers; | ||
let Request; | ||
let Response; | ||
@@ -59,2 +60,12 @@ let stream; | ||
function toRequest(url, options) { | ||
var request; | ||
if (Request.prototype.isPrototypeOf(url)) { | ||
request = url; | ||
} else { | ||
request = new Request(url, options); | ||
} | ||
return request; | ||
} | ||
function compileRoute (route) { | ||
@@ -66,4 +77,4 @@ | ||
method = method.toLowerCase(); | ||
matchMethod = function(options) { | ||
var m = options && options.method ? options.method.toLowerCase() : 'get'; | ||
matchMethod = function(req) { | ||
var m = req && req.method ? req.method.toLowerCase() : 'get'; | ||
return m === method; | ||
@@ -96,3 +107,4 @@ }; | ||
route.matcher = function (url, options) { | ||
return matchMethod(options) && url.indexOf(expectedUrl) === 0; | ||
var req = toRequest(url, options); | ||
return matchMethod(req) && req.url.indexOf(expectedUrl) === 0; | ||
}; | ||
@@ -102,3 +114,4 @@ } else { | ||
route.matcher = function (url, options) { | ||
return matchMethod(options) && url === expectedUrl; | ||
var req = toRequest(url, options); | ||
return matchMethod(req) && req.url === expectedUrl; | ||
}; | ||
@@ -110,3 +123,4 @@ } | ||
route.matcher = function (url, options) { | ||
return matchMethod(options) && urlRX.test(url); | ||
var req = toRequest(url, options); | ||
return matchMethod(req) && urlRX.test(req.url); | ||
}; | ||
@@ -120,2 +134,3 @@ } | ||
Headers = opts.Headers; | ||
Request = opts.Request; | ||
Response = opts.Response; | ||
@@ -122,0 +137,0 @@ stream = opts.stream; |
'use strict'; | ||
const Request = require('node-fetch').Request; | ||
const Response = require('node-fetch').Response; | ||
@@ -10,2 +11,3 @@ const Headers = require('node-fetch').Headers; | ||
theGlobal: GLOBAL, | ||
Request: Request, | ||
Response: Response, | ||
@@ -12,0 +14,0 @@ Headers: Headers, |
@@ -36,7 +36,7 @@ 'use strict'; | ||
expect(function () { | ||
mock('url', {prop: 'val'}) | ||
mock('http://url', {prop: 'val'}) | ||
}).not.to.throw(); | ||
expect(fetchMock.calls().unmatched.length).to.equal(1); | ||
expect(fetchCalls.length).to.equal(1); | ||
expect(fetchCalls[0]).to.eql(['url', {prop: 'val'}]); | ||
expect(fetchCalls[0]).to.eql(['http://url', {prop: 'val'}]); | ||
@@ -43,0 +43,0 @@ fetchMock.restore(); |
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
63688
1645