Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

axios-mock-adapter

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-mock-adapter - npm Package Compare versions

Comparing version 1.21.4 to 1.21.5

2

dist/axios-mock-adapter.js

@@ -61,3 +61,3 @@ /*

"use strict";
eval("\n\nvar handleRequest = __webpack_require__(/*! ./handle_request */ \"./src/handle_request.js\");\nvar utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nvar VERBS = [\n \"get\",\n \"post\",\n \"head\",\n \"delete\",\n \"patch\",\n \"put\",\n \"options\",\n \"list\",\n \"link\",\n \"unlink\",\n];\n\nfunction adapter() {\n return function (config) {\n var mockAdapter = this;\n return new Promise(function (resolve, reject) {\n handleRequest(mockAdapter, resolve, reject, config);\n });\n }.bind(this);\n}\n\nfunction getVerbObject() {\n return VERBS.reduce(function (accumulator, verb) {\n accumulator[verb] = [];\n return accumulator;\n }, {});\n}\n\nfunction reset() {\n resetHandlers.call(this);\n resetHistory.call(this);\n}\n\nfunction resetHandlers() {\n this.handlers = getVerbObject();\n}\n\nfunction resetHistory() {\n this.history = getVerbObject();\n}\n\nfunction MockAdapter(axiosInstance, options) {\n reset.call(this);\n\n if (axiosInstance) {\n this.axiosInstance = axiosInstance;\n // Clone the axios instance to remove interceptors\n // this is used for the passThrough mode with axios > 1.2\n this.axiosInstanceWithoutInterceptors = axiosInstance.create\n ? axiosInstance.create()\n : undefined;\n\n this.originalAdapter = axiosInstance.defaults.adapter;\n this.delayResponse =\n options && options.delayResponse > 0 ? options.delayResponse : null;\n this.onNoMatch = (options && options.onNoMatch) || null;\n axiosInstance.defaults.adapter = this.adapter.call(this);\n } else {\n throw new Error(\"Please provide an instance of axios to mock\");\n }\n}\n\nMockAdapter.prototype.adapter = adapter;\n\nMockAdapter.prototype.restore = function restore() {\n if (this.axiosInstance) {\n this.axiosInstance.defaults.adapter = this.originalAdapter;\n this.axiosInstance = undefined;\n }\n};\n\nMockAdapter.prototype.reset = reset;\nMockAdapter.prototype.resetHandlers = resetHandlers;\nMockAdapter.prototype.resetHistory = resetHistory;\n\nVERBS.concat(\"any\").forEach(function (method) {\n var methodName = \"on\" + method.charAt(0).toUpperCase() + method.slice(1);\n MockAdapter.prototype[methodName] = function (matcher, body, requestHeaders) {\n var _this = this;\n var matcher = matcher === undefined ? /.*/ : matcher;\n\n function reply(code, response, headers) {\n var handler = [matcher, body, requestHeaders, code, response, headers];\n addHandler(method, _this.handlers, handler);\n return _this;\n }\n\n function replyOnce(code, response, headers) {\n var handler = [\n matcher,\n body,\n requestHeaders,\n code,\n response,\n headers,\n true,\n ];\n addHandler(method, _this.handlers, handler);\n return _this;\n }\n\n return {\n reply: reply,\n\n replyOnce: replyOnce,\n\n passThrough: function passThrough() {\n var handler = [matcher, body];\n addHandler(method, _this.handlers, handler);\n return _this;\n },\n\n abortRequest: function () {\n return reply(function (config) {\n var error = utils.createAxiosError(\n \"Request aborted\",\n config,\n undefined,\n \"ECONNABORTED\"\n );\n return Promise.reject(error);\n });\n },\n\n abortRequestOnce: function () {\n return replyOnce(function (config) {\n var error = utils.createAxiosError(\n \"Request aborted\",\n config,\n undefined,\n \"ECONNABORTED\"\n );\n return Promise.reject(error);\n });\n },\n\n networkError: function () {\n return reply(function (config) {\n var error = utils.createAxiosError(\"Network Error\", config);\n return Promise.reject(error);\n });\n },\n\n networkErrorOnce: function () {\n return replyOnce(function (config) {\n var error = utils.createAxiosError(\"Network Error\", config);\n return Promise.reject(error);\n });\n },\n\n timeout: function () {\n return reply(function (config) {\n var error = utils.createAxiosError(\n config.timeoutErrorMessage ||\n \"timeout of \" + config.timeout + \"ms exceeded\",\n config,\n undefined,\n \"ECONNABORTED\"\n );\n return Promise.reject(error);\n });\n },\n\n timeoutOnce: function () {\n return replyOnce(function (config) {\n var error = utils.createAxiosError(\n config.timeoutErrorMessage ||\n \"timeout of \" + config.timeout + \"ms exceeded\",\n config,\n undefined,\n \"ECONNABORTED\"\n );\n return Promise.reject(error);\n });\n },\n };\n };\n});\n\nfunction findInHandlers(method, handlers, handler) {\n var index = -1;\n for (var i = 0; i < handlers[method].length; i += 1) {\n var item = handlers[method][i];\n var isReplyOnce = item.length === 7;\n var comparePaths =\n item[0] instanceof RegExp && handler[0] instanceof RegExp\n ? String(item[0]) === String(handler[0])\n : item[0] === handler[0];\n var isSame =\n comparePaths &&\n utils.isEqual(item[1], handler[1]) &&\n utils.isEqual(item[2], handler[2]);\n if (isSame && !isReplyOnce) {\n index = i;\n }\n }\n return index;\n}\n\nfunction addHandler(method, handlers, handler) {\n if (method === \"any\") {\n VERBS.forEach(function (verb) {\n handlers[verb].push(handler);\n });\n } else {\n var indexOfExistingHandler = findInHandlers(method, handlers, handler);\n if (indexOfExistingHandler > -1 && handler.length < 7) {\n handlers[method].splice(indexOfExistingHandler, 1, handler);\n } else {\n handlers[method].push(handler);\n }\n }\n}\n\nmodule.exports = MockAdapter;\nmodule.exports[\"default\"] = MockAdapter;\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/index.js?");
eval("\n\nvar handleRequest = __webpack_require__(/*! ./handle_request */ \"./src/handle_request.js\");\nvar utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nvar VERBS = [\n \"get\",\n \"post\",\n \"head\",\n \"delete\",\n \"patch\",\n \"put\",\n \"options\",\n \"list\",\n \"link\",\n \"unlink\",\n];\n\nfunction adapter() {\n return function (config) {\n var mockAdapter = this;\n return new Promise(function (resolve, reject) {\n handleRequest(mockAdapter, resolve, reject, config);\n });\n }.bind(this);\n}\n\nfunction getVerbObject() {\n return VERBS.reduce(function (accumulator, verb) {\n accumulator[verb] = [];\n return accumulator;\n }, {});\n}\n\nfunction reset() {\n resetHandlers.call(this);\n resetHistory.call(this);\n}\n\nfunction resetHandlers() {\n this.handlers = getVerbObject();\n}\n\nfunction resetHistory() {\n this.history = getVerbObject();\n}\n\nfunction MockAdapter(axiosInstance, options) {\n reset.call(this);\n\n if (axiosInstance) {\n this.axiosInstance = axiosInstance;\n // Clone the axios instance to remove interceptors\n // this is used for the passThrough mode with axios > 1.2\n this.axiosInstanceWithoutInterceptors = axiosInstance.create\n ? axiosInstance.create()\n : undefined;\n\n this.originalAdapter = axiosInstance.defaults.adapter;\n this.delayResponse =\n options && options.delayResponse > 0 ? options.delayResponse : null;\n this.onNoMatch = (options && options.onNoMatch) || null;\n axiosInstance.defaults.adapter = this.adapter.call(this);\n } else {\n throw new Error(\"Please provide an instance of axios to mock\");\n }\n}\n\nMockAdapter.prototype.adapter = adapter;\n\nMockAdapter.prototype.restore = function restore() {\n if (this.axiosInstance) {\n this.axiosInstance.defaults.adapter = this.originalAdapter;\n this.axiosInstance = undefined;\n }\n};\n\nMockAdapter.prototype.reset = reset;\nMockAdapter.prototype.resetHandlers = resetHandlers;\nMockAdapter.prototype.resetHistory = resetHistory;\n\nVERBS.concat(\"any\").forEach(function (method) {\n var methodName = \"on\" + method.charAt(0).toUpperCase() + method.slice(1);\n MockAdapter.prototype[methodName] = function (matcher, body, requestHeaders) {\n var _this = this;\n var matcher = matcher === undefined ? /.*/ : matcher;\n\n function reply(code, response, headers) {\n var handler = [matcher, body, requestHeaders, code, response, headers];\n addHandler(method, _this.handlers, handler);\n return _this;\n }\n\n function replyOnce(code, response, headers) {\n var handler = [\n matcher,\n body,\n requestHeaders,\n code,\n response,\n headers,\n true,\n ];\n addHandler(method, _this.handlers, handler);\n return _this;\n }\n\n return {\n reply: reply,\n\n replyOnce: replyOnce,\n\n passThrough: function passThrough() {\n var handler = [matcher, body];\n addHandler(method, _this.handlers, handler);\n return _this;\n },\n\n abortRequest: function () {\n return reply(function (config) {\n var error = utils.createAxiosError(\n \"Request aborted\",\n config,\n undefined,\n \"ECONNABORTED\"\n );\n return Promise.reject(error);\n });\n },\n\n abortRequestOnce: function () {\n return replyOnce(function (config) {\n var error = utils.createAxiosError(\n \"Request aborted\",\n config,\n undefined,\n \"ECONNABORTED\"\n );\n return Promise.reject(error);\n });\n },\n\n networkError: function () {\n return reply(function (config) {\n var error = utils.createAxiosError(\"Network Error\", config);\n return Promise.reject(error);\n });\n },\n\n networkErrorOnce: function () {\n return replyOnce(function (config) {\n var error = utils.createAxiosError(\"Network Error\", config);\n return Promise.reject(error);\n });\n },\n\n timeout: function () {\n return reply(function (config) {\n var error = utils.createAxiosError(\n config.timeoutErrorMessage ||\n \"timeout of \" + config.timeout + \"ms exceeded\",\n config,\n undefined,\n config.transitional && config.transitional.clarifyTimeoutError\n ? \"ETIMEDOUT\"\n : \"ECONNABORTED\"\n );\n return Promise.reject(error);\n });\n },\n\n timeoutOnce: function () {\n return replyOnce(function (config) {\n var error = utils.createAxiosError(\n config.timeoutErrorMessage ||\n \"timeout of \" + config.timeout + \"ms exceeded\",\n config,\n undefined,\n config.transitional && config.transitional.clarifyTimeoutError\n ? \"ETIMEDOUT\"\n : \"ECONNABORTED\"\n );\n return Promise.reject(error);\n });\n },\n };\n };\n});\n\nfunction findInHandlers(method, handlers, handler) {\n var index = -1;\n for (var i = 0; i < handlers[method].length; i += 1) {\n var item = handlers[method][i];\n var isReplyOnce = item.length === 7;\n var comparePaths =\n item[0] instanceof RegExp && handler[0] instanceof RegExp\n ? String(item[0]) === String(handler[0])\n : item[0] === handler[0];\n var isSame =\n comparePaths &&\n utils.isEqual(item[1], handler[1]) &&\n utils.isEqual(item[2], handler[2]);\n if (isSame && !isReplyOnce) {\n index = i;\n }\n }\n return index;\n}\n\nfunction addHandler(method, handlers, handler) {\n if (method === \"any\") {\n VERBS.forEach(function (verb) {\n handlers[verb].push(handler);\n });\n } else {\n var indexOfExistingHandler = findInHandlers(method, handlers, handler);\n if (indexOfExistingHandler > -1 && handler.length < 7) {\n handlers[method].splice(indexOfExistingHandler, 1, handler);\n } else {\n handlers[method].push(handler);\n }\n }\n}\n\nmodule.exports = MockAdapter;\nmodule.exports[\"default\"] = MockAdapter;\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/index.js?");

@@ -64,0 +64,0 @@ /***/ }),

/*! For license information please see axios-mock-adapter.min.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("axios")):"function"==typeof define&&define.amd?define(["axios"],t):"object"==typeof exports?exports.AxiosMockAdapter=t(require("axios")):e.AxiosMockAdapter=t(e.axios)}(self,(e=>{return t={63:e=>{"use strict";e.exports=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!=o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!=o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=n;0!=o--;){var s=i[o];if(!e(t[s],r[s]))return!1}return!0}return t!=t&&r!=r}},738:e=>{e.exports=function(e){return null!=e&&null!=e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}},141:(e,t,r)=>{"use strict";var n=r(555);function o(e,t){return{status:e[0],data:(r=e[1],n.isArrayBuffer(r)||n.isBuffer(r)||n.isStream(r)||n.isBlob(r)?r:n.isObjectOrArray(r)?JSON.parse(JSON.stringify(r)):r),headers:e[2],config:t,request:{responseURL:t.url}};var r}function i(e,t,r,n){var o=n.baseURL;if(n.baseURL&&!/^https?:/.test(n.baseURL)&&(o=void 0),"function"==typeof e.originalAdapter)return e.originalAdapter(n).then(t,r);e.axiosInstanceWithoutInterceptors(Object.assign({},n,{baseURL:o,adapter:e.originalAdapter,transformRequest:[],transformResponse:[]})).then(t,r)}e.exports=function(e,t,r,s){var a=s.url||"";s.baseURL&&a.substr(0,s.baseURL.length)===s.baseURL&&(a=a.slice(s.baseURL.length)),delete s.adapter,e.history[s.method].push(s);var u=n.findHandler(e.handlers,s.method,a,s.data,s.params,s.headers&&"AxiosHeaders"===s.headers.constructor.name?Object.assign({},s.headers):s.headers,s.baseURL);if(u)if(7===u.length&&n.purgeIfReplyOnce(e,u),2===u.length)i(e,t,r,s);else if("function"!=typeof u[3])n.settle(t,r,o(u.slice(3),s),e.delayResponse);else{var c=u[3](s);"function"!=typeof c.then?n.settle(t,r,o(c,s),e.delayResponse):c.then((function(i){i.config&&i.status?n.settle(t,r,o([i.status,i.data,i.headers],i.config),0):n.settle(t,r,o(i,s),e.delayResponse)}),(function(t){e.delayResponse>0?setTimeout((function(){r(t)}),e.delayResponse):r(t)}))}else switch(e.onNoMatch){case"passthrough":i(e,t,r,s);break;case"throwException":throw n.createCouldNotFindMockError(s);default:n.settle(t,r,{status:404,config:s},e.delayResponse)}}},138:(e,t,r)=>{"use strict";var n=r(141),o=r(555),i=["get","post","head","delete","patch","put","options","list","link","unlink"];function s(){return i.reduce((function(e,t){return e[t]=[],e}),{})}function a(){u.call(this),c.call(this)}function u(){this.handlers=s()}function c(){this.history=s()}function f(e,t){if(a.call(this),!e)throw new Error("Please provide an instance of axios to mock");this.axiosInstance=e,this.axiosInstanceWithoutInterceptors=e.create?e.create():void 0,this.originalAdapter=e.defaults.adapter,this.delayResponse=t&&t.delayResponse>0?t.delayResponse:null,this.onNoMatch=t&&t.onNoMatch||null,e.defaults.adapter=this.adapter.call(this)}function l(e,t,r){if("any"===e)i.forEach((function(e){t[e].push(r)}));else{var n=function(e,t,r){for(var n=-1,i=0;i<t[e].length;i+=1){var s=t[e][i],a=7===s.length;(s[0]instanceof RegExp&&r[0]instanceof RegExp?String(s[0])===String(r[0]):s[0]===r[0])&&o.isEqual(s[1],r[1])&&o.isEqual(s[2],r[2])&&!a&&(n=i)}return n}(e,t,r);n>-1&&r.length<7?t[e].splice(n,1,r):t[e].push(r)}}f.prototype.adapter=function(){return function(e){var t=this;return new Promise((function(r,o){n(t,r,o,e)}))}.bind(this)},f.prototype.restore=function(){this.axiosInstance&&(this.axiosInstance.defaults.adapter=this.originalAdapter,this.axiosInstance=void 0)},f.prototype.reset=a,f.prototype.resetHandlers=u,f.prototype.resetHistory=c,i.concat("any").forEach((function(e){var t="on"+e.charAt(0).toUpperCase()+e.slice(1);f.prototype[t]=function(t,r,n){var i=this;function s(o,s,a){var u=[t,r,n,o,s,a];return l(e,i.handlers,u),i}function a(o,s,a){var u=[t,r,n,o,s,a,!0];return l(e,i.handlers,u),i}return t=void 0===t?/.*/:t,{reply:s,replyOnce:a,passThrough:function(){var n=[t,r];return l(e,i.handlers,n),i},abortRequest:function(){return s((function(e){var t=o.createAxiosError("Request aborted",e,void 0,"ECONNABORTED");return Promise.reject(t)}))},abortRequestOnce:function(){return a((function(e){var t=o.createAxiosError("Request aborted",e,void 0,"ECONNABORTED");return Promise.reject(t)}))},networkError:function(){return s((function(e){var t=o.createAxiosError("Network Error",e);return Promise.reject(t)}))},networkErrorOnce:function(){return a((function(e){var t=o.createAxiosError("Network Error",e);return Promise.reject(t)}))},timeout:function(){return s((function(e){var t=o.createAxiosError(e.timeoutErrorMessage||"timeout of "+e.timeout+"ms exceeded",e,void 0,"ECONNABORTED");return Promise.reject(t)}))},timeoutOnce:function(){return a((function(e){var t=o.createAxiosError(e.timeoutErrorMessage||"timeout of "+e.timeout+"ms exceeded",e,void 0,"ECONNABORTED");return Promise.reject(t)}))}}}})),e.exports=f,e.exports.default=f},376:e=>{e.exports=function(e){return"undefined"!=typeof Blob&&(e instanceof Blob||"[object Blob]"===Object.prototype.toString.call(e))}},555:(e,t,r)=>{"use strict";var n=r(300),o=r(63),i=r(738),s=r(376),a=Object.prototype.toString;function u(e,t){for(var r=e.length,n=0;n<r;n++){var o=e[n];if(t(o))return o}}function c(e){return"[object Function]"===a.call(e)}function f(e){return null!==e&&"object"==typeof e}function l(e,t){return e?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):t}function p(e,t){return("/"===e[0]?e.substr(1):e)===("/"===t[0]?t.substr(1):t)}function d(e,t,r,n){if(["delete","get","head","options"].indexOf(e.toLowerCase())>=0){var o=n?n.data:void 0;return h(r,n?n.params:void 0)&&y(t,o)}return y(t,n)}function h(e,t){return void 0===t||("function"==typeof t.asymmetricMatch?t.asymmetricMatch(e):o(e,t))}function y(e,t){if(void 0===t)return!0;var r;try{r=JSON.parse(e)}catch(e){}return h(r||e,t)}function v(e,t,r,o){if("function"==typeof n.AxiosError)return n.AxiosError.from(new Error(e),o,t,null,r);var i=new Error(e);return i.isAxiosError=!0,i.config=t,void 0!==r&&(i.response=r),void 0!==o&&(i.code=o),i.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},i}e.exports={find:u,findHandler:function(e,t,r,n,o,i,s){return u(e[t.toLowerCase()],(function(e){return"string"==typeof e[0]?(p(r,e[0])||p(l(s,r),e[0]))&&d(t,n,o,e[1])&&h(i,e[2]):e[0]instanceof RegExp?(e[0].test(r)||e[0].test(l(s,r)))&&d(t,n,o,e[1])&&h(i,e[2]):void 0}))},purgeIfReplyOnce:function(e,t){Object.keys(e.handlers).forEach((function(r){var n=e.handlers[r].indexOf(t);n>-1&&e.handlers[r].splice(n,1)}))},settle:function e(t,r,n,o){o>0?setTimeout(e,o,t,r,n):!n.config.validateStatus||n.config.validateStatus(n.status)?t(n):r(v("Request failed with status code "+n.status,n.config,n))},isStream:function(e){return f(e)&&c(e.pipe)},isArrayBuffer:function(e){return"[object ArrayBuffer]"===a.call(e)},isFunction:c,isObjectOrArray:f,isBuffer:i,isBlob:s,isBodyOrParametersMatching:d,isEqual:o,createAxiosError:v,createCouldNotFindMockError:function(e){var t="Could not find mock for: \n"+JSON.stringify(e,["method","url"],2),r=new Error(t);return r.isCouldNotFindMockError=!0,r.url=e.url,r.method=e.method,r}}},300:t=>{"use strict";t.exports=e}},r={},function e(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return t[n](i,i.exports,e),i.exports}(138);var t,r}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("axios")):"function"==typeof define&&define.amd?define(["axios"],t):"object"==typeof exports?exports.AxiosMockAdapter=t(require("axios")):e.AxiosMockAdapter=t(e.axios)}(self,(e=>{return t={63:e=>{"use strict";e.exports=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!=o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!=o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=n;0!=o--;){var s=i[o];if(!e(t[s],r[s]))return!1}return!0}return t!=t&&r!=r}},738:e=>{e.exports=function(e){return null!=e&&null!=e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}},141:(e,t,r)=>{"use strict";var n=r(555);function o(e,t){return{status:e[0],data:(r=e[1],n.isArrayBuffer(r)||n.isBuffer(r)||n.isStream(r)||n.isBlob(r)?r:n.isObjectOrArray(r)?JSON.parse(JSON.stringify(r)):r),headers:e[2],config:t,request:{responseURL:t.url}};var r}function i(e,t,r,n){var o=n.baseURL;if(n.baseURL&&!/^https?:/.test(n.baseURL)&&(o=void 0),"function"==typeof e.originalAdapter)return e.originalAdapter(n).then(t,r);e.axiosInstanceWithoutInterceptors(Object.assign({},n,{baseURL:o,adapter:e.originalAdapter,transformRequest:[],transformResponse:[]})).then(t,r)}e.exports=function(e,t,r,s){var a=s.url||"";s.baseURL&&a.substr(0,s.baseURL.length)===s.baseURL&&(a=a.slice(s.baseURL.length)),delete s.adapter,e.history[s.method].push(s);var u=n.findHandler(e.handlers,s.method,a,s.data,s.params,s.headers&&"AxiosHeaders"===s.headers.constructor.name?Object.assign({},s.headers):s.headers,s.baseURL);if(u)if(7===u.length&&n.purgeIfReplyOnce(e,u),2===u.length)i(e,t,r,s);else if("function"!=typeof u[3])n.settle(t,r,o(u.slice(3),s),e.delayResponse);else{var c=u[3](s);"function"!=typeof c.then?n.settle(t,r,o(c,s),e.delayResponse):c.then((function(i){i.config&&i.status?n.settle(t,r,o([i.status,i.data,i.headers],i.config),0):n.settle(t,r,o(i,s),e.delayResponse)}),(function(t){e.delayResponse>0?setTimeout((function(){r(t)}),e.delayResponse):r(t)}))}else switch(e.onNoMatch){case"passthrough":i(e,t,r,s);break;case"throwException":throw n.createCouldNotFindMockError(s);default:n.settle(t,r,{status:404,config:s},e.delayResponse)}}},138:(e,t,r)=>{"use strict";var n=r(141),o=r(555),i=["get","post","head","delete","patch","put","options","list","link","unlink"];function s(){return i.reduce((function(e,t){return e[t]=[],e}),{})}function a(){u.call(this),c.call(this)}function u(){this.handlers=s()}function c(){this.history=s()}function f(e,t){if(a.call(this),!e)throw new Error("Please provide an instance of axios to mock");this.axiosInstance=e,this.axiosInstanceWithoutInterceptors=e.create?e.create():void 0,this.originalAdapter=e.defaults.adapter,this.delayResponse=t&&t.delayResponse>0?t.delayResponse:null,this.onNoMatch=t&&t.onNoMatch||null,e.defaults.adapter=this.adapter.call(this)}function l(e,t,r){if("any"===e)i.forEach((function(e){t[e].push(r)}));else{var n=function(e,t,r){for(var n=-1,i=0;i<t[e].length;i+=1){var s=t[e][i],a=7===s.length;(s[0]instanceof RegExp&&r[0]instanceof RegExp?String(s[0])===String(r[0]):s[0]===r[0])&&o.isEqual(s[1],r[1])&&o.isEqual(s[2],r[2])&&!a&&(n=i)}return n}(e,t,r);n>-1&&r.length<7?t[e].splice(n,1,r):t[e].push(r)}}f.prototype.adapter=function(){return function(e){var t=this;return new Promise((function(r,o){n(t,r,o,e)}))}.bind(this)},f.prototype.restore=function(){this.axiosInstance&&(this.axiosInstance.defaults.adapter=this.originalAdapter,this.axiosInstance=void 0)},f.prototype.reset=a,f.prototype.resetHandlers=u,f.prototype.resetHistory=c,i.concat("any").forEach((function(e){var t="on"+e.charAt(0).toUpperCase()+e.slice(1);f.prototype[t]=function(t,r,n){var i=this;function s(o,s,a){var u=[t,r,n,o,s,a];return l(e,i.handlers,u),i}function a(o,s,a){var u=[t,r,n,o,s,a,!0];return l(e,i.handlers,u),i}return t=void 0===t?/.*/:t,{reply:s,replyOnce:a,passThrough:function(){var n=[t,r];return l(e,i.handlers,n),i},abortRequest:function(){return s((function(e){var t=o.createAxiosError("Request aborted",e,void 0,"ECONNABORTED");return Promise.reject(t)}))},abortRequestOnce:function(){return a((function(e){var t=o.createAxiosError("Request aborted",e,void 0,"ECONNABORTED");return Promise.reject(t)}))},networkError:function(){return s((function(e){var t=o.createAxiosError("Network Error",e);return Promise.reject(t)}))},networkErrorOnce:function(){return a((function(e){var t=o.createAxiosError("Network Error",e);return Promise.reject(t)}))},timeout:function(){return s((function(e){var t=o.createAxiosError(e.timeoutErrorMessage||"timeout of "+e.timeout+"ms exceeded",e,void 0,e.transitional&&e.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED");return Promise.reject(t)}))},timeoutOnce:function(){return a((function(e){var t=o.createAxiosError(e.timeoutErrorMessage||"timeout of "+e.timeout+"ms exceeded",e,void 0,e.transitional&&e.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED");return Promise.reject(t)}))}}}})),e.exports=f,e.exports.default=f},376:e=>{e.exports=function(e){return"undefined"!=typeof Blob&&(e instanceof Blob||"[object Blob]"===Object.prototype.toString.call(e))}},555:(e,t,r)=>{"use strict";var n=r(300),o=r(63),i=r(738),s=r(376),a=Object.prototype.toString;function u(e,t){for(var r=e.length,n=0;n<r;n++){var o=e[n];if(t(o))return o}}function c(e){return"[object Function]"===a.call(e)}function f(e){return null!==e&&"object"==typeof e}function l(e,t){return e?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):t}function p(e,t){return("/"===e[0]?e.substr(1):e)===("/"===t[0]?t.substr(1):t)}function d(e,t,r,n){if(["delete","get","head","options"].indexOf(e.toLowerCase())>=0){var o=n?n.data:void 0;return h(r,n?n.params:void 0)&&y(t,o)}return y(t,n)}function h(e,t){return void 0===t||("function"==typeof t.asymmetricMatch?t.asymmetricMatch(e):o(e,t))}function y(e,t){if(void 0===t)return!0;var r;try{r=JSON.parse(e)}catch(e){}return h(r||e,t)}function m(e,t,r,o){if("function"==typeof n.AxiosError)return n.AxiosError.from(new Error(e),o,t,null,r);var i=new Error(e);return i.isAxiosError=!0,i.config=t,void 0!==r&&(i.response=r),void 0!==o&&(i.code=o),i.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},i}e.exports={find:u,findHandler:function(e,t,r,n,o,i,s){return u(e[t.toLowerCase()],(function(e){return"string"==typeof e[0]?(p(r,e[0])||p(l(s,r),e[0]))&&d(t,n,o,e[1])&&h(i,e[2]):e[0]instanceof RegExp?(e[0].test(r)||e[0].test(l(s,r)))&&d(t,n,o,e[1])&&h(i,e[2]):void 0}))},purgeIfReplyOnce:function(e,t){Object.keys(e.handlers).forEach((function(r){var n=e.handlers[r].indexOf(t);n>-1&&e.handlers[r].splice(n,1)}))},settle:function e(t,r,n,o){o>0?setTimeout(e,o,t,r,n):!n.config.validateStatus||n.config.validateStatus(n.status)?t(n):r(m("Request failed with status code "+n.status,n.config,n))},isStream:function(e){return f(e)&&c(e.pipe)},isArrayBuffer:function(e){return"[object ArrayBuffer]"===a.call(e)},isFunction:c,isObjectOrArray:f,isBuffer:i,isBlob:s,isBodyOrParametersMatching:d,isEqual:o,createAxiosError:m,createCouldNotFindMockError:function(e){var t="Could not find mock for: \n"+JSON.stringify(e,["method","url"],2),r=new Error(t);return r.isCouldNotFindMockError=!0,r.url=e.url,r.method=e.method,r}}},300:t=>{"use strict";t.exports=e}},r={},function e(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return t[n](i,i.exports,e),i.exports}(138);var t,r}));
{
"name": "axios-mock-adapter",
"version": "1.21.4",
"version": "1.21.5",
"description": "Axios adapter that allows to easily mock requests",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -164,3 +164,5 @@ "use strict";

undefined,
"ECONNABORTED"
config.transitional && config.transitional.clarifyTimeoutError
? "ETIMEDOUT"
: "ECONNABORTED"
);

@@ -178,3 +180,5 @@ return Promise.reject(error);

undefined,
"ECONNABORTED"
config.transitional && config.transitional.clarifyTimeoutError
? "ETIMEDOUT"
: "ECONNABORTED"
);

@@ -181,0 +185,0 @@ return Promise.reject(error);

@@ -58,2 +58,4 @@ import { AxiosAdapter, AxiosInstance, AxiosRequestConfig } from 'axios';

declare class MockAdapter {
static default: typeof MockAdapter;
constructor(axiosInstance: AxiosInstance, options?: MockAdapterOptions);

@@ -60,0 +62,0 @@

@@ -5,3 +5,4 @@ import axios from 'axios';

const instance = axios.create();
const mock = new MockAdapter(instance);
let mock = new MockAdapter(instance);
mock = new MockAdapter.default(instance)

@@ -8,0 +9,0 @@ namespace AllowsConstructing {

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