axios-mock-adapter
Advanced tools
Comparing version 1.16.0 to 1.17.0
@@ -140,3 +140,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
"use strict"; | ||
eval("\n\nvar utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nfunction makeResponse(result, config) {\n return {\n status: result[0],\n data: utils.isSimpleObject(result[1]) ? JSON.parse(JSON.stringify(result[1])) : result[1],\n headers: result[2],\n config: config\n };\n}\n\nfunction handleRequest(mockAdapter, resolve, reject, config) {\n var url = config.url;\n if (config.baseURL && config.url.substr(0, config.baseURL.length) === config.baseURL) {\n url = config.url.slice(config.baseURL ? config.baseURL.length : 0);\n }\n\n delete config.adapter;\n mockAdapter.history[config.method].push(config);\n\n var handler = utils.findHandler(\n mockAdapter.handlers,\n config.method,\n url,\n config.data,\n config.params,\n config.headers,\n config.baseURL\n );\n\n if (handler) {\n if (handler.length === 7) {\n utils.purgeIfReplyOnce(mockAdapter, handler);\n }\n\n if (handler.length === 2) {\n // passThrough handler\n // tell axios to use the original adapter instead of our mock, fixes #35\n config.adapter = mockAdapter.originalAdapter;\n mockAdapter.axiosInstance.request(config).then(resolve, reject);\n } else if (typeof handler[3] !== 'function') {\n utils.settle(\n resolve,\n reject,\n makeResponse(handler.slice(3), config),\n mockAdapter.delayResponse\n );\n } else {\n var result = handler[3](config);\n // TODO throw a sane exception when return value is incorrect\n if (typeof result.then !== 'function') {\n utils.settle(resolve, reject, makeResponse(result, config), mockAdapter.delayResponse);\n } else {\n result.then(\n function(result) {\n if (result.config && result.status) {\n utils.settle(resolve, reject, makeResponse([result.status, result.data, result.headers], result.config), 0);\n } else {\n utils.settle(resolve, reject, makeResponse(result, config), mockAdapter.delayResponse);\n }\n },\n function(error) {\n if (mockAdapter.delayResponse > 0) {\n setTimeout(function() {\n reject(error);\n }, mockAdapter.delayResponse);\n } else {\n reject(error);\n }\n }\n );\n }\n }\n } else {\n // handler not found\n utils.settle(\n resolve,\n reject,\n {\n status: 404,\n config: config\n },\n mockAdapter.delayResponse\n );\n }\n}\n\nmodule.exports = handleRequest;\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/handle_request.js?"); | ||
eval("\n\nvar utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nfunction makeResponse(result, config) {\n return {\n status: result[0],\n data: utils.isSimpleObject(result[1]) ? JSON.parse(JSON.stringify(result[1])) : result[1],\n headers: result[2],\n config: config\n };\n}\n\nfunction handleRequest(mockAdapter, resolve, reject, config) {\n var url = config.url;\n if (config.baseURL && config.url.substr(0, config.baseURL.length) === config.baseURL) {\n url = config.url.slice(config.baseURL ? config.baseURL.length : 0);\n }\n\n delete config.adapter;\n mockAdapter.history[config.method].push(config);\n\n var handler = utils.findHandler(\n mockAdapter.handlers,\n config.method,\n url,\n config.data,\n config.params,\n config.headers,\n config.baseURL\n );\n\n if (handler) {\n if (handler.length === 7) {\n utils.purgeIfReplyOnce(mockAdapter, handler);\n }\n\n if (handler.length === 2) {\n // passThrough handler\n mockAdapter.originalAdapter(config).then(resolve, reject);\n } else if (typeof handler[3] !== 'function') {\n utils.settle(\n resolve,\n reject,\n makeResponse(handler.slice(3), config),\n mockAdapter.delayResponse\n );\n } else {\n var result = handler[3](config);\n // TODO throw a sane exception when return value is incorrect\n if (typeof result.then !== 'function') {\n utils.settle(resolve, reject, makeResponse(result, config), mockAdapter.delayResponse);\n } else {\n result.then(\n function(result) {\n if (result.config && result.status) {\n utils.settle(resolve, reject, makeResponse([result.status, result.data, result.headers], result.config), 0);\n } else {\n utils.settle(resolve, reject, makeResponse(result, config), mockAdapter.delayResponse);\n }\n },\n function(error) {\n if (mockAdapter.delayResponse > 0) {\n setTimeout(function() {\n reject(error);\n }, mockAdapter.delayResponse);\n } else {\n reject(error);\n }\n }\n );\n }\n }\n } else {\n // handler not found\n utils.settle(\n resolve,\n reject,\n {\n status: 404,\n config: config\n },\n mockAdapter.delayResponse\n );\n }\n}\n\nmodule.exports = handleRequest;\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/handle_request.js?"); | ||
@@ -143,0 +143,0 @@ /***/ }), |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("axios")):"function"==typeof define&&define.amd?define(["axios"],n):"object"==typeof exports?exports.AxiosMockAdapter=n(require("axios")):t.AxiosMockAdapter=n(t.axios)}(window,function(t){return function(t){var n={};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}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return 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,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=1)}([function(t,n,e){var r=Array.prototype.slice,o=e(2),i=e(3),u=t.exports=function(t,n,e){return e||(e={}),t===n||(t instanceof Date&&n instanceof Date?t.getTime()===n.getTime():!t||!n||"object"!=typeof t&&"object"!=typeof n?e.strict?t===n:t==n:function(t,n,e){var s,c;if(f(t)||f(n))return!1;if(t.prototype!==n.prototype)return!1;if(i(t))return!!i(n)&&(t=r.call(t),n=r.call(n),u(t,n,e));if(a(t)){if(!a(n))return!1;if(t.length!==n.length)return!1;for(s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}try{var p=o(t),y=o(n)}catch(t){return!1}if(p.length!=y.length)return!1;for(p.sort(),y.sort(),s=p.length-1;s>=0;s--)if(p[s]!=y[s])return!1;for(s=p.length-1;s>=0;s--)if(c=p[s],!u(t[c],n[c],e))return!1;return typeof t==typeof n}(t,n,e))};function f(t){return null==t}function a(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(t,n,e){"use strict";var r=e(0),o=e(4),i=["get","post","head","delete","patch","put","options","list"];function u(){return i.reduce(function(t,n){return t[n]=[],t},{})}function f(){a.call(this),s.call(this)}function a(){this.handlers=u()}function s(){this.history=u()}function c(t,n){f.call(this),t&&(this.axiosInstance=t,this.originalAdapter=t.defaults.adapter,this.delayResponse=n&&n.delayResponse>0?n.delayResponse:null,t.defaults.adapter=this.adapter.call(this))}function p(t,n,e){if("any"===t)i.forEach(function(t){n[t].push(e)});else{var o=function(t,n,e){for(var o=-1,i=0;i<n[t].length;i+=1){var u=n[t][i],f=7===u.length;(u[0]instanceof RegExp&&e[0]instanceof RegExp?String(u[0])===String(e[0]):u[0]===e[0])&&r(u[1],e[1],{strict:!0})&&r(u[2],e[2],{strict:!0})&&!f&&(o=i)}return o}(t,n,e);o>-1&&e.length<7?n[t].splice(o,1,e):n[t].push(e)}}c.prototype.adapter=function(){return function(t){var n=this;if(3!==arguments.length)return new Promise(function(e,r){o(n,e,r,t)});o(n,arguments[0],arguments[1],arguments[2])}.bind(this)},c.prototype.restore=function(){this.axiosInstance&&(this.axiosInstance.defaults.adapter=this.originalAdapter)},c.prototype.reset=f,c.prototype.resetHandlers=a,c.prototype.resetHistory=s,i.concat("any").forEach(function(t){var n="on"+t.charAt(0).toUpperCase()+t.slice(1);c.prototype[n]=function(n,e,r){var o=this;n=void 0===n?/.*/:n;function i(i,u,f){var a=[n,e,r,i,u,f];return p(t,o.handlers,a),o}function u(i,u,f){var a=[n,e,r,i,u,f,!0];return p(t,o.handlers,a),o}return{reply:i,replyOnce:u,passThrough:function(){var r=[n,e];return p(t,o.handlers,r),o},networkError:function(){i(function(t){var n=new Error("Network Error");return n.config=t,Promise.reject(n)})},networkErrorOnce:function(){u(function(t){var n=new Error("Network Error");return n.config=t,Promise.reject(n)})},timeout:function(){i(function(t){var n=new Error("timeout of "+t.timeout+"ms exceeded");return n.config=t,n.code="ECONNABORTED",Promise.reject(n)})},timeoutOnce:function(){u(function(t){var n=new Error("timeout of "+t.timeout+"ms exceeded");return n.config=t,n.code="ECONNABORTED",Promise.reject(n)})}}}}),t.exports=c,t.exports.default=c},function(t,n){function e(t){var n=[];for(var e in t)n.push(e);return n}(t.exports="function"==typeof Object.keys?Object.keys:e).shim=e},function(t,n){var e="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();function r(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function o(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Object.prototype.hasOwnProperty.call(t,"callee")&&!Object.prototype.propertyIsEnumerable.call(t,"callee")||!1}(n=t.exports=e?r:o).supported=r,n.unsupported=o},function(t,n,e){"use strict";var r=e(5);function o(t,n){return{status:t[0],data:r.isSimpleObject(t[1])?JSON.parse(JSON.stringify(t[1])):t[1],headers:t[2],config:n}}t.exports=function(t,n,e,i){var u=i.url;i.baseURL&&i.url.substr(0,i.baseURL.length)===i.baseURL&&(u=i.url.slice(i.baseURL?i.baseURL.length:0)),delete i.adapter,t.history[i.method].push(i);var f=r.findHandler(t.handlers,i.method,u,i.data,i.params,i.headers,i.baseURL);if(f)if(7===f.length&&r.purgeIfReplyOnce(t,f),2===f.length)i.adapter=t.originalAdapter,t.axiosInstance.request(i).then(n,e);else if("function"!=typeof f[3])r.settle(n,e,o(f.slice(3),i),t.delayResponse);else{var a=f[3](i);"function"!=typeof a.then?r.settle(n,e,o(a,i),t.delayResponse):a.then(function(u){u.config&&u.status?r.settle(n,e,o([u.status,u.data,u.headers],u.config),0):r.settle(n,e,o(u,i),t.delayResponse)},function(n){t.delayResponse>0?setTimeout(function(){e(n)},t.delayResponse):e(n)})}else r.settle(n,e,{status:404,config:i},t.delayResponse)}},function(t,n,e){"use strict";var r=e(6),o=e(0);function i(t,n){return o(t,n,{strict:!0})}var u=!!r.create().defaults.headers;function f(t,n){for(var e=t.length,r=0;r<e;r++){var o=t[r];if(n(o))return o}}function a(t,n){return t?t.replace(/\/+$/,"")+"/"+n.replace(/^\/+/,""):n}function s(t,n){return("/"===t[0]?t.substr(1):t)===("/"===n[0]?n.substr(1):n)}function c(t,n){return void 0===n||i(t,n)}function p(t,n,e,r){return["delete","get","head","options"].indexOf(t.toLowerCase())>=0?function(t,n){return void 0===n||i(t,n)}(e,r?r.params:void 0):function(t,n){if(void 0===n)return!0;var e;try{e=JSON.parse(t)}catch(t){}return i(e||t,n)}(n,r)}t.exports={find:f,findHandler:function(t,n,e,r,o,i,u){return f(t[n.toLowerCase()],function(t){return"string"==typeof t[0]?(s(e,t[0])||s(a(u,e),t[0]))&&p(n,r,o,t[1])&&c(i,t[2]):t[0]instanceof RegExp?(t[0].test(e)||t[0].test(a(u,e)))&&p(n,r,o,t[1])&&c(i,t[2]):void 0})},isSimpleObject:function(t){return null!=t&&"[object Object]"===t.toString()},purgeIfReplyOnce:function(t,n){Object.keys(t.handlers).forEach(function(e){var r=t.handlers[e].indexOf(n);r>-1&&t.handlers[e].splice(r,1)})},settle:function t(n,e,r,o){o>0?setTimeout(function(){t(n,e,r)},o):r.config&&r.config.validateStatus?r.config.validateStatus(r.status)?n(r):e(function(t,n,e){if(!u)return e;var r=new Error(t);return r.config=n,r.response=e,r}("Request failed with status code "+r.status,r.config,r)):r.status>=200&&r.status<300?n(r):e(r)}}},function(n,e){n.exports=t}])}); | ||
!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)}(window,function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){var r=Array.prototype.slice,o=n(2),i=n(3),u=e.exports=function(e,t,n){return n||(n={}),e===t||(e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():!e||!t||"object"!=typeof e&&"object"!=typeof t?n.strict?e===t:e==t:function(e,t,n){var a,f;if(s(e)||s(t))return!1;if(e.prototype!==t.prototype)return!1;if(i(e))return!!i(t)&&(e=r.call(e),t=r.call(t),u(e,t,n));if(c(e)){if(!c(t))return!1;if(e.length!==t.length)return!1;for(a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}try{var l=o(e),p=o(t)}catch(e){return!1}if(l.length!=p.length)return!1;for(l.sort(),p.sort(),a=l.length-1;a>=0;a--)if(l[a]!=p[a])return!1;for(a=l.length-1;a>=0;a--)if(f=l[a],!u(e[f],t[f],n))return!1;return typeof e==typeof t}(e,t,n))};function s(e){return null==e}function c(e){return!(!e||"object"!=typeof e||"number"!=typeof e.length)&&("function"==typeof e.copy&&"function"==typeof e.slice&&!(e.length>0&&"number"!=typeof e[0]))}},function(e,t,n){"use strict";var r=n(0),o=n(4),i=["get","post","head","delete","patch","put","options","list"];function u(){return i.reduce(function(e,t){return e[t]=[],e},{})}function s(){c.call(this),a.call(this)}function c(){this.handlers=u()}function a(){this.history=u()}function f(e,t){s.call(this),e&&(this.axiosInstance=e,this.originalAdapter=e.defaults.adapter,this.delayResponse=t&&t.delayResponse>0?t.delayResponse:null,e.defaults.adapter=this.adapter.call(this))}function l(e,t,n){if("any"===e)i.forEach(function(e){t[e].push(n)});else{var o=function(e,t,n){for(var o=-1,i=0;i<t[e].length;i+=1){var u=t[e][i],s=7===u.length;(u[0]instanceof RegExp&&n[0]instanceof RegExp?String(u[0])===String(n[0]):u[0]===n[0])&&r(u[1],n[1],{strict:!0})&&r(u[2],n[2],{strict:!0})&&!s&&(o=i)}return o}(e,t,n);o>-1&&n.length<7?t[e].splice(o,1,n):t[e].push(n)}}f.prototype.adapter=function(){return function(e){var t=this;if(3!==arguments.length)return new Promise(function(n,r){o(t,n,r,e)});o(t,arguments[0],arguments[1],arguments[2])}.bind(this)},f.prototype.restore=function(){this.axiosInstance&&(this.axiosInstance.defaults.adapter=this.originalAdapter)},f.prototype.reset=s,f.prototype.resetHandlers=c,f.prototype.resetHistory=a,i.concat("any").forEach(function(e){var t="on"+e.charAt(0).toUpperCase()+e.slice(1);f.prototype[t]=function(t,n,r){var o=this;t=void 0===t?/.*/:t;function i(i,u,s){var c=[t,n,r,i,u,s];return l(e,o.handlers,c),o}function u(i,u,s){var c=[t,n,r,i,u,s,!0];return l(e,o.handlers,c),o}return{reply:i,replyOnce:u,passThrough:function(){var r=[t,n];return l(e,o.handlers,r),o},networkError:function(){i(function(e){var t=new Error("Network Error");return t.config=e,Promise.reject(t)})},networkErrorOnce:function(){u(function(e){var t=new Error("Network Error");return t.config=e,Promise.reject(t)})},timeout:function(){i(function(e){var t=new Error("timeout of "+e.timeout+"ms exceeded");return t.config=e,t.code="ECONNABORTED",Promise.reject(t)})},timeoutOnce:function(){u(function(e){var t=new Error("timeout of "+e.timeout+"ms exceeded");return t.config=e,t.code="ECONNABORTED",Promise.reject(t)})}}}}),e.exports=f,e.exports.default=f},function(e,t){function n(e){var t=[];for(var n in e)t.push(n);return t}(e.exports="function"==typeof Object.keys?Object.keys:n).shim=n},function(e,t){var n="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();function r(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function o(e){return e&&"object"==typeof e&&"number"==typeof e.length&&Object.prototype.hasOwnProperty.call(e,"callee")&&!Object.prototype.propertyIsEnumerable.call(e,"callee")||!1}(t=e.exports=n?r:o).supported=r,t.unsupported=o},function(e,t,n){"use strict";var r=n(5);function o(e,t){return{status:e[0],data:r.isSimpleObject(e[1])?JSON.parse(JSON.stringify(e[1])):e[1],headers:e[2],config:t}}e.exports=function(e,t,n,i){var u=i.url;i.baseURL&&i.url.substr(0,i.baseURL.length)===i.baseURL&&(u=i.url.slice(i.baseURL?i.baseURL.length:0)),delete i.adapter,e.history[i.method].push(i);var s=r.findHandler(e.handlers,i.method,u,i.data,i.params,i.headers,i.baseURL);if(s)if(7===s.length&&r.purgeIfReplyOnce(e,s),2===s.length)e.originalAdapter(i).then(t,n);else if("function"!=typeof s[3])r.settle(t,n,o(s.slice(3),i),e.delayResponse);else{var c=s[3](i);"function"!=typeof c.then?r.settle(t,n,o(c,i),e.delayResponse):c.then(function(u){u.config&&u.status?r.settle(t,n,o([u.status,u.data,u.headers],u.config),0):r.settle(t,n,o(u,i),e.delayResponse)},function(t){e.delayResponse>0?setTimeout(function(){n(t)},e.delayResponse):n(t)})}else r.settle(t,n,{status:404,config:i},e.delayResponse)}},function(e,t,n){"use strict";var r=n(6),o=n(0);function i(e,t){return o(e,t,{strict:!0})}var u=!!r.create().defaults.headers;function s(e,t){for(var n=e.length,r=0;r<n;r++){var o=e[r];if(t(o))return o}}function c(e,t){return e?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):t}function a(e,t){return("/"===e[0]?e.substr(1):e)===("/"===t[0]?t.substr(1):t)}function f(e,t){return void 0===t||i(e,t)}function l(e,t,n,r){return["delete","get","head","options"].indexOf(e.toLowerCase())>=0?function(e,t){return void 0===t||i(e,t)}(n,r?r.params:void 0):function(e,t){if(void 0===t)return!0;var n;try{n=JSON.parse(e)}catch(e){}return i(n||e,t)}(t,r)}e.exports={find:s,findHandler:function(e,t,n,r,o,i,u){return s(e[t.toLowerCase()],function(e){return"string"==typeof e[0]?(a(n,e[0])||a(c(u,n),e[0]))&&l(t,r,o,e[1])&&f(i,e[2]):e[0]instanceof RegExp?(e[0].test(n)||e[0].test(c(u,n)))&&l(t,r,o,e[1])&&f(i,e[2]):void 0})},isSimpleObject:function(e){return null!=e&&"[object Object]"===e.toString()},purgeIfReplyOnce:function(e,t){Object.keys(e.handlers).forEach(function(n){var r=e.handlers[n].indexOf(t);r>-1&&e.handlers[n].splice(r,1)})},settle:function e(t,n,r,o){o>0?setTimeout(function(){e(t,n,r)},o):r.config&&r.config.validateStatus?r.config.validateStatus(r.status)?t(r):n(function(e,t,n){if(!u)return n;var r=new Error(e);return r.config=t,r.response=n,r}("Request failed with status code "+r.status,r.config,r)):r.status>=200&&r.status<300?t(r):n(r)}}},function(t,n){t.exports=e}])}); |
{ | ||
"name": "axios-mock-adapter", | ||
"version": "1.16.0", | ||
"version": "1.17.0", | ||
"description": "Axios adapter that allows to easily mock requests", | ||
@@ -43,7 +43,7 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"axios": "^0.18.0", | ||
"axios": "^0.19.0", | ||
"chai": "^4.1.0", | ||
"eslint": "^5.2.0", | ||
"eslint": "^6.0.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^5.2.0", | ||
"mocha": "^6.1.4", | ||
"rimraf": "^2.6.1", | ||
@@ -50,0 +50,0 @@ "webpack": "^4.16.4", |
@@ -82,5 +82,11 @@ # axios-mock-adapter | ||
You can also reset the registered mock handlers with `reset` | ||
You can also reset the registered mock handlers with `resetHandlers` | ||
```js | ||
mock.resetHandlers(); | ||
``` | ||
You can reset both registered mock handlers and history items with `reset` | ||
```js | ||
mock.reset(); | ||
@@ -97,2 +103,5 @@ ``` | ||
mock.onGet('/users').networkError(); | ||
// networkErrorOnce can be used to mock a network error only once | ||
mock.onGet('/users').networkErrorOnce(); | ||
``` | ||
@@ -105,2 +114,5 @@ | ||
mock.onGet('/users').timeout(); | ||
// timeoutOnce can be used to mock a timeout only once | ||
mock.onGet('/users').timeoutOnce(); | ||
``` | ||
@@ -303,1 +315,7 @@ | ||
``` | ||
You can clear the history with `resetHistory` | ||
```js | ||
mock.resetHistory(); | ||
``` |
@@ -40,5 +40,3 @@ 'use strict'; | ||
// passThrough handler | ||
// tell axios to use the original adapter instead of our mock, fixes #35 | ||
config.adapter = mockAdapter.originalAdapter; | ||
mockAdapter.axiosInstance.request(config).then(resolve, reject); | ||
mockAdapter.originalAdapter(config).then(resolve, reject); | ||
} else if (typeof handler[3] !== 'function') { | ||
@@ -45,0 +43,0 @@ utils.settle( |
@@ -16,8 +16,7 @@ import { AxiosAdapter, AxiosInstance, AxiosRequestConfig } from 'axios'; | ||
replyOnce: ResponseSpecFunc; | ||
timeoutOnce: ResponseSpecFunc; | ||
networkErrorOnce: ResponseSpecFunc; | ||
passThrough(): MockAdapter; | ||
networkError(): MockAdapter; | ||
timeout(): MockAdapter; | ||
networkError(): void; | ||
networkErrorOnce(): void; | ||
timeout(): void; | ||
timeoutOnce(): void; | ||
} | ||
@@ -51,6 +50,8 @@ | ||
reset(): void; | ||
resetHandlers(): void; | ||
resetHistory(): void; | ||
restore(): void; | ||
history: { [method:string]:AxiosRequestConfig[]; }; | ||
history: { [method: string]: AxiosRequestConfig[] }; | ||
onGet: RequestMatcherFunc; | ||
@@ -57,0 +58,0 @@ onPost: RequestMatcherFunc; |
@@ -25,2 +25,10 @@ import axios from 'axios'; | ||
namespace SupportsResetHandlers { | ||
mock.resetHandlers(); | ||
} | ||
namespace SupportsResetHistory { | ||
mock.resetHistory(); | ||
} | ||
namespace SupportsRestore { | ||
@@ -27,0 +35,0 @@ mock.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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
54580
714
318