axios-mock-adapter
Advanced tools
Comparing version 1.14.1 to 1.15.0
@@ -204,4 +204,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
function reset() { | ||
this.handlers = VERBS.reduce(function(accumulator, verb) { | ||
function getVerbObject() { | ||
return VERBS.reduce(function(accumulator, verb) { | ||
accumulator[verb] = []; | ||
@@ -212,2 +212,15 @@ return accumulator; | ||
function reset() { | ||
resetHandlers.call(this); | ||
resetHistory.call(this); | ||
} | ||
function resetHandlers() { | ||
this.handlers = getVerbObject(); | ||
} | ||
function resetHistory() { | ||
this.history = getVerbObject(); | ||
} | ||
function MockAdapter(axiosInstance, options) { | ||
@@ -233,2 +246,4 @@ reset.call(this); | ||
MockAdapter.prototype.reset = reset; | ||
MockAdapter.prototype.resetHandlers = resetHandlers; | ||
MockAdapter.prototype.resetHistory = resetHistory; | ||
@@ -384,4 +399,6 @@ VERBS.concat('any').forEach(function(method) { | ||
} | ||
config.adapter = null; | ||
delete config.adapter; | ||
mockAdapter.history[config.method].push(config); | ||
var handler = utils.findHandler( | ||
@@ -388,0 +405,0 @@ mockAdapter.handlers, |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("axios")):"function"==typeof define&&define.amd?define(["axios"],e):"object"==typeof exports?exports.AxiosMockAdapter=e(require("axios")):t.AxiosMockAdapter=e(t.axios)}("undefined"!=typeof self?self:this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=1)}([function(t,e,n){function r(t){return null===t||void 0===t}function o(t){return!(!t||"object"!=typeof t||"number"!=typeof t.length)&&("function"==typeof t.copy&&"function"==typeof t.slice&&!(t.length>0&&"number"!=typeof t[0]))}function i(t,e,n){var i,f;if(r(t)||r(e))return!1;if(t.prototype!==e.prototype)return!1;if(a(t))return!!a(e)&&(t=s.call(t),e=s.call(e),c(t,e,n));if(o(t)){if(!o(e))return!1;if(t.length!==e.length)return!1;for(i=0;i<t.length;i++)if(t[i]!==e[i])return!1;return!0}try{var l=u(t),p=u(e)}catch(t){return!1}if(l.length!=p.length)return!1;for(l.sort(),p.sort(),i=l.length-1;i>=0;i--)if(l[i]!=p[i])return!1;for(i=l.length-1;i>=0;i--)if(f=l[i],!c(t[f],e[f],n))return!1;return typeof t==typeof e}var s=Array.prototype.slice,u=n(2),a=n(3),c=t.exports=function(t,e,n){return n||(n={}),t===e||(t instanceof Date&&e instanceof Date?t.getTime()===e.getTime():!t||!e||"object"!=typeof t&&"object"!=typeof e?n.strict?t===e:t==e:i(t,e,n))}},function(t,e,n){"use strict";function r(){return function(t){var e=this;if(3!==arguments.length)return new Promise(function(n,r){c(e,n,r,t)});c(e,arguments[0],arguments[1],arguments[2])}.bind(this)}function o(){this.handlers=f.reduce(function(t,e){return t[e]=[],t},{})}function i(t,e){o.call(this),t&&(this.axiosInstance=t,this.originalAdapter=t.defaults.adapter,this.delayResponse=e&&e.delayResponse>0?e.delayResponse:null,t.defaults.adapter=this.adapter.call(this))}function s(t,e,n){for(var r=-1,o=0;o<e[t].length;o+=1){var i=e[t][o],s=7===i.length;(i[0]instanceof RegExp&&n[0]instanceof RegExp?String(i[0])===String(n[0]):i[0]===n[0])&&a(i[1],n[1],{strict:!0})&&a(i[2],n[2],{strict:!0})&&!s&&(r=o)}return r}function u(t,e,n){if("any"===t)f.forEach(function(t){e[t].push(n)});else{var r=s(t,e,n);r>-1&&n.length<7?e[t].splice(r,1,n):e[t].push(n)}}var a=n(0),c=n(4),f=["get","post","head","delete","patch","put","options"];i.prototype.adapter=r,i.prototype.restore=function(){this.axiosInstance&&(this.axiosInstance.defaults.adapter=this.originalAdapter)},i.prototype.reset=o,f.concat("any").forEach(function(t){var e="on"+t.charAt(0).toUpperCase()+t.slice(1);i.prototype[e]=function(e,n,r){function o(o,s,a){var c=[e,n,r,o,s,a];return u(t,i.handlers,c),i}var i=this,e=void 0===e?/.*/:e;return{reply:o,replyOnce:function(o,s,a){var c=[e,n,r,o,s,a,!0];return u(t,i.handlers,c),i},passThrough:function(){var r=[e,n];return u(t,i.handlers,r),i},networkError:function(){o(function(t){var e=new Error("Network Error");return e.config=t,Promise.reject(e)})},timeout:function(){o(function(t){var e=new Error("timeout of "+t.timeout+"ms exceeded");return e.config=t,e.code="ECONNABORTED",Promise.reject(e)})}}}}),t.exports=i,t.exports.default=i},function(t,e){function n(t){var e=[];for(var n in t)e.push(n);return e}e=t.exports="function"==typeof Object.keys?Object.keys:n,e.shim=n},function(t,e){function n(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function r(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Object.prototype.hasOwnProperty.call(t,"callee")&&!Object.prototype.propertyIsEnumerable.call(t,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();e=t.exports=o?n:r,e.supported=n,e.unsupported=r},function(t,e,n){"use strict";function r(t,e){return{status:t[0],data:i.isSimpleObject(t[1])?JSON.parse(JSON.stringify(t[1])):t[1],headers:t[2],config:e}}function o(t,e,n,o){o.baseURL&&o.url.substr(0,o.baseURL.length)===o.baseURL&&(o.url=o.url.slice(o.baseURL?o.baseURL.length:0)),o.adapter=null;var s=i.findHandler(t.handlers,o.method,o.url,o.data,o.params,o.headers,o.baseURL);if(s)if(7===s.length&&i.purgeIfReplyOnce(t,s),2===s.length)o.adapter=t.originalAdapter,t.axiosInstance.request(o).then(e,n);else if(s[3]instanceof Function){var u=s[3](o);u.then instanceof Function?u.then(function(s){i.settle(e,n,r(s,o),t.delayResponse)},function(e){t.delayResponse>0?setTimeout(function(){n(e)},t.delayResponse):n(e)}):i.settle(e,n,r(u,o),t.delayResponse)}else i.settle(e,n,r(s.slice(3),o),t.delayResponse);else i.settle(e,n,{status:404,config:o},t.delayResponse)}var i=n(5);t.exports=o},function(t,e,n){"use strict";function r(t,e){return v(t,e,{strict:!0})}function o(t,e){for(var n=t.length,r=0;r<n;r++){var o=t[r];if(e(o))return o}}function i(t,e){return t?t.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,""):e}function s(t,e,n,r,s,f,l){return o(t[e.toLowerCase()],function(t){return"string"==typeof t[0]?(u(n,t[0])||u(i(l,n),t[0]))&&c(e,r,s,t[1])&&a(f,t[2]):t[0]instanceof RegExp?(t[0].test(n)||t[0].test(i(l,n)))&&c(e,r,s,t[1])&&a(f,t[2]):void 0})}function u(t,e){return("/"===t[0]?t.substr(1):t)===("/"===e[0]?e.substr(1):e)}function a(t,e){return void 0===e||r(t,e)}function c(t,e,n,r){if(["delete","get","head","options"].indexOf(t.toLowerCase())>=0)return f(n,r?r.params:void 0);return l(e,r)}function f(t,e){return void 0===e||r(t,e)}function l(t,e){if(void 0===e)return!0;var n;try{n=JSON.parse(t)}catch(t){}return n?r(n,e):r(t,e)}function p(t,e){Object.keys(t.handlers).forEach(function(n){var r=t.handlers[n].indexOf(e);r>-1&&t.handlers[n].splice(r,1)})}function d(t,e,n,r){return r>0?void setTimeout(function(){d(t,e,n)},r):n.config&&n.config.validateStatus?void(n.config.validateStatus(n.status)?t(n):e(h("Request failed with status code "+n.status,n.config,n))):void(n.status>=200&&n.status<300?t(n):e(n))}function h(t,e,n){if(!b)return n;var r=new Error(t);return r.config=e,r.response=n,r}function y(t){return null!==t&&void 0!==t&&"[object Object]"===t.toString()}var g=n(6),v=n(0),b=!!g.create().defaults.headers;t.exports={find:o,findHandler:s,isSimpleObject:y,purgeIfReplyOnce:p,settle:d}},function(e,n){e.exports=t}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("axios")):"function"==typeof define&&define.amd?define(["axios"],e):"object"==typeof exports?exports.AxiosMockAdapter=e(require("axios")):t.AxiosMockAdapter=e(t.axios)}("undefined"!=typeof self?self:this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=1)}([function(t,e,n){function r(t){return null===t||void 0===t}function o(t){return!(!t||"object"!=typeof t||"number"!=typeof t.length)&&("function"==typeof t.copy&&"function"==typeof t.slice&&!(t.length>0&&"number"!=typeof t[0]))}function i(t,e,n){var i,f;if(r(t)||r(e))return!1;if(t.prototype!==e.prototype)return!1;if(a(t))return!!a(e)&&(t=s.call(t),e=s.call(e),c(t,e,n));if(o(t)){if(!o(e))return!1;if(t.length!==e.length)return!1;for(i=0;i<t.length;i++)if(t[i]!==e[i])return!1;return!0}try{var p=u(t),l=u(e)}catch(t){return!1}if(p.length!=l.length)return!1;for(p.sort(),l.sort(),i=p.length-1;i>=0;i--)if(p[i]!=l[i])return!1;for(i=p.length-1;i>=0;i--)if(f=p[i],!c(t[f],e[f],n))return!1;return typeof t==typeof e}var s=Array.prototype.slice,u=n(2),a=n(3),c=t.exports=function(t,e,n){return n||(n={}),t===e||(t instanceof Date&&e instanceof Date?t.getTime()===e.getTime():!t||!e||"object"!=typeof t&&"object"!=typeof e?n.strict?t===e:t==e:i(t,e,n))}},function(t,e,n){"use strict";function r(){return function(t){var e=this;if(3!==arguments.length)return new Promise(function(n,r){l(e,n,r,t)});l(e,arguments[0],arguments[1],arguments[2])}.bind(this)}function o(){return d.reduce(function(t,e){return t[e]=[],t},{})}function i(){s.call(this),u.call(this)}function s(){this.handlers=o()}function u(){this.history=o()}function a(t,e){i.call(this),t&&(this.axiosInstance=t,this.originalAdapter=t.defaults.adapter,this.delayResponse=e&&e.delayResponse>0?e.delayResponse:null,t.defaults.adapter=this.adapter.call(this))}function c(t,e,n){for(var r=-1,o=0;o<e[t].length;o+=1){var i=e[t][o],s=7===i.length;(i[0]instanceof RegExp&&n[0]instanceof RegExp?String(i[0])===String(n[0]):i[0]===n[0])&&p(i[1],n[1],{strict:!0})&&p(i[2],n[2],{strict:!0})&&!s&&(r=o)}return r}function f(t,e,n){if("any"===t)d.forEach(function(t){e[t].push(n)});else{var r=c(t,e,n);r>-1&&n.length<7?e[t].splice(r,1,n):e[t].push(n)}}var p=n(0),l=n(4),d=["get","post","head","delete","patch","put","options"];a.prototype.adapter=r,a.prototype.restore=function(){this.axiosInstance&&(this.axiosInstance.defaults.adapter=this.originalAdapter)},a.prototype.reset=i,a.prototype.resetHandlers=s,a.prototype.resetHistory=u,d.concat("any").forEach(function(t){var e="on"+t.charAt(0).toUpperCase()+t.slice(1);a.prototype[e]=function(e,n,r){function o(o,s,u){var a=[e,n,r,o,s,u];return f(t,i.handlers,a),i}var i=this,e=void 0===e?/.*/:e;return{reply:o,replyOnce:function(o,s,u){var a=[e,n,r,o,s,u,!0];return f(t,i.handlers,a),i},passThrough:function(){var r=[e,n];return f(t,i.handlers,r),i},networkError:function(){o(function(t){var e=new Error("Network Error");return e.config=t,Promise.reject(e)})},timeout:function(){o(function(t){var e=new Error("timeout of "+t.timeout+"ms exceeded");return e.config=t,e.code="ECONNABORTED",Promise.reject(e)})}}}}),t.exports=a,t.exports.default=a},function(t,e){function n(t){var e=[];for(var n in t)e.push(n);return e}e=t.exports="function"==typeof Object.keys?Object.keys:n,e.shim=n},function(t,e){function n(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function r(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Object.prototype.hasOwnProperty.call(t,"callee")&&!Object.prototype.propertyIsEnumerable.call(t,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();e=t.exports=o?n:r,e.supported=n,e.unsupported=r},function(t,e,n){"use strict";function r(t,e){return{status:t[0],data:i.isSimpleObject(t[1])?JSON.parse(JSON.stringify(t[1])):t[1],headers:t[2],config:e}}function o(t,e,n,o){o.baseURL&&o.url.substr(0,o.baseURL.length)===o.baseURL&&(o.url=o.url.slice(o.baseURL?o.baseURL.length:0)),delete o.adapter,t.history[o.method].push(o);var s=i.findHandler(t.handlers,o.method,o.url,o.data,o.params,o.headers,o.baseURL);if(s)if(7===s.length&&i.purgeIfReplyOnce(t,s),2===s.length)o.adapter=t.originalAdapter,t.axiosInstance.request(o).then(e,n);else if(s[3]instanceof Function){var u=s[3](o);u.then instanceof Function?u.then(function(s){i.settle(e,n,r(s,o),t.delayResponse)},function(e){t.delayResponse>0?setTimeout(function(){n(e)},t.delayResponse):n(e)}):i.settle(e,n,r(u,o),t.delayResponse)}else i.settle(e,n,r(s.slice(3),o),t.delayResponse);else i.settle(e,n,{status:404,config:o},t.delayResponse)}var i=n(5);t.exports=o},function(t,e,n){"use strict";function r(t,e){return v(t,e,{strict:!0})}function o(t,e){for(var n=t.length,r=0;r<n;r++){var o=t[r];if(e(o))return o}}function i(t,e){return t?t.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,""):e}function s(t,e,n,r,s,f,p){return o(t[e.toLowerCase()],function(t){return"string"==typeof t[0]?(u(n,t[0])||u(i(p,n),t[0]))&&c(e,r,s,t[1])&&a(f,t[2]):t[0]instanceof RegExp?(t[0].test(n)||t[0].test(i(p,n)))&&c(e,r,s,t[1])&&a(f,t[2]):void 0})}function u(t,e){return("/"===t[0]?t.substr(1):t)===("/"===e[0]?e.substr(1):e)}function a(t,e){return void 0===e||r(t,e)}function c(t,e,n,r){if(["delete","get","head","options"].indexOf(t.toLowerCase())>=0)return f(n,r?r.params:void 0);return p(e,r)}function f(t,e){return void 0===e||r(t,e)}function p(t,e){if(void 0===e)return!0;var n;try{n=JSON.parse(t)}catch(t){}return n?r(n,e):r(t,e)}function l(t,e){Object.keys(t.handlers).forEach(function(n){var r=t.handlers[n].indexOf(e);r>-1&&t.handlers[n].splice(r,1)})}function d(t,e,n,r){return r>0?void setTimeout(function(){d(t,e,n)},r):n.config&&n.config.validateStatus?void(n.config.validateStatus(n.status)?t(n):e(h("Request failed with status code "+n.status,n.config,n))):void(n.status>=200&&n.status<300?t(n):e(n))}function h(t,e,n){if(!b)return n;var r=new Error(t);return r.config=e,r.response=n,r}function y(t){return null!==t&&void 0!==t&&"[object Object]"===t.toString()}var g=n(6),v=n(0),b=!!g.create().defaults.headers;t.exports={find:o,findHandler:s,isSimpleObject:y,purgeIfReplyOnce:l,settle:d}},function(e,n){e.exports=t}])}); |
{ | ||
"name": "axios-mock-adapter", | ||
"version": "1.14.1", | ||
"version": "1.15.0", | ||
"description": "Axios adapter that allows to easily mock requests", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -18,4 +18,6 @@ 'use strict'; | ||
} | ||
config.adapter = null; | ||
delete config.adapter; | ||
mockAdapter.history[config.method].push(config); | ||
var handler = utils.findHandler( | ||
@@ -22,0 +24,0 @@ mockAdapter.handlers, |
@@ -24,4 +24,4 @@ 'use strict'; | ||
function reset() { | ||
this.handlers = VERBS.reduce(function(accumulator, verb) { | ||
function getVerbObject() { | ||
return VERBS.reduce(function(accumulator, verb) { | ||
accumulator[verb] = []; | ||
@@ -32,2 +32,15 @@ return accumulator; | ||
function reset() { | ||
resetHandlers.call(this); | ||
resetHistory.call(this); | ||
} | ||
function resetHandlers() { | ||
this.handlers = getVerbObject(); | ||
} | ||
function resetHistory() { | ||
this.history = getVerbObject(); | ||
} | ||
function MockAdapter(axiosInstance, options) { | ||
@@ -53,2 +66,4 @@ reset.call(this); | ||
MockAdapter.prototype.reset = reset; | ||
MockAdapter.prototype.resetHandlers = resetHandlers; | ||
MockAdapter.prototype.resetHistory = resetHistory; | ||
@@ -55,0 +70,0 @@ VERBS.concat('any').forEach(function(method) { |
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
47079
988