Socket
Socket
Sign inDemoInstall

axios-mock-adapter

Package Overview
Dependencies
Maintainers
1
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.14.0 to 1.14.1

10

dist/axios-mock-adapter.js

@@ -394,3 +394,8 @@ (function webpackUniversalModuleDefinition(root, factory) {

if (handler) {
if (handler.length === 2) { // passThrough handler
if (handler.length === 7) {
utils.purgeIfReplyOnce(mockAdapter, handler);
}
if (handler.length === 2) {
// passThrough handler
// tell axios to use the original adapter instead of our mock, fixes #35

@@ -400,5 +405,2 @@ config.adapter = mockAdapter.originalAdapter;

} else if (!(handler[3] instanceof Function)) {
if (handler.length === 7) {
utils.purgeIfReplyOnce(mockAdapter, handler);
}
utils.settle(

@@ -405,0 +407,0 @@ resolve,

2

dist/axios-mock-adapter.min.js

@@ -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(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 7===s.length&&i.purgeIfReplyOnce(t,s),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 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}])});
{
"name": "axios-mock-adapter",
"version": "1.14.0",
"version": "1.14.1",
"description": "Axios adapter that allows to easily mock requests",

@@ -43,3 +43,3 @@ "main": "src/index.js",

"devDependencies": {
"axios": "^0.17.0",
"axios": "^0.18.0",
"chai": "^4.1.0",

@@ -46,0 +46,0 @@ "cross-env": "^5.1.0",

@@ -31,3 +31,8 @@ 'use strict';

if (handler) {
if (handler.length === 2) { // passThrough handler
if (handler.length === 7) {
utils.purgeIfReplyOnce(mockAdapter, handler);
}
if (handler.length === 2) {
// passThrough handler
// tell axios to use the original adapter instead of our mock, fixes #35

@@ -37,5 +42,2 @@ config.adapter = mockAdapter.originalAdapter;

} else if (!(handler[3] instanceof Function)) {
if (handler.length === 7) {
utils.purgeIfReplyOnce(mockAdapter, handler);
}
utils.settle(

@@ -42,0 +44,0 @@ resolve,

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