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.22.0 to 2.0.0

6

dist/axios-mock-adapter.js

@@ -50,3 +50,3 @@ /*

"use strict";
eval("\n\nvar utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nfunction transformRequest(data) {\n if (\n utils.isArrayBuffer(data) ||\n utils.isBuffer(data) ||\n utils.isStream(data) ||\n utils.isBlob(data)\n ) {\n return data;\n }\n\n // Object and Array: returns a deep copy\n if (utils.isObjectOrArray(data)) {\n return JSON.parse(JSON.stringify(data));\n }\n\n // for primitives like string, undefined, null, number\n return data;\n}\n\nfunction makeResponse(result, config) {\n return {\n status: result[0],\n data: transformRequest(result[1]),\n headers: result[2],\n config: config,\n request: {\n responseURL: config.url,\n },\n };\n}\n\nfunction passThroughRequest (mockAdapter, resolve, reject, config) {\n // Axios v0.17 mutates the url to include the baseURL for non hostnames\n // but does not remove the baseURL from the config\n var baseURL = config.baseURL;\n if (config.baseURL && !/^https?:/.test(config.baseURL)) {\n baseURL = undefined;\n }\n\n // Axios pre 1.2\n if (typeof mockAdapter.originalAdapter === 'function') {\n return mockAdapter.originalAdapter(config).then(resolve, reject);\n }\n\n mockAdapter.axiosInstanceWithoutInterceptors(Object.assign({}, config, {\n baseURL: baseURL,\n // Use the original adapter, not the mock adapter\n adapter: mockAdapter.originalAdapter,\n // The request transformation runs on the original axios handler already\n transformRequest: [],\n transformResponse: []\n })).then(resolve, reject);\n}\n\nfunction handleRequest(mockAdapter, resolve, reject, config) {\n var url = config.url || \"\";\n // TODO we're not hitting this `if` in any of the tests, investigate\n if (\n config.baseURL &&\n url.substr(0, config.baseURL.length) === config.baseURL\n ) {\n url = url.slice(config.baseURL.length);\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 && config.headers.constructor.name === 'AxiosHeaders')\n ? Object.assign({}, config.headers)\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 passThroughRequest(mockAdapter, resolve, reject, config);\n } else if (typeof handler[3] !== \"function\") {\n utils.settle(\n resolve,\n reject,\n makeResponse(handler.slice(3), config),\n getEffectiveDelay(mockAdapter, handler)\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(\n resolve,\n reject,\n makeResponse(result, config),\n getEffectiveDelay(mockAdapter, handler)\n );\n } else {\n result.then(\n function (result) {\n if (result.config && result.status) {\n utils.settle(\n resolve,\n reject,\n makeResponse(\n [result.status, result.data, result.headers],\n result.config\n ),\n 0\n );\n } else {\n utils.settle(\n resolve,\n reject,\n makeResponse(result, config),\n getEffectiveDelay(mockAdapter, handler)\n );\n }\n },\n function (error) {\n if (mockAdapter.delayResponse > 0) {\n setTimeout(function () {\n reject(error);\n }, getEffectiveDelay(mockAdapter, handler));\n } else {\n reject(error);\n }\n }\n );\n }\n }\n } else {\n // handler not found\n switch (mockAdapter.onNoMatch) {\n case \"passthrough\":\n passThroughRequest(mockAdapter, resolve, reject, config);\n break;\n case \"throwException\":\n throw utils.createCouldNotFindMockError(config);\n default:\n utils.settle(\n resolve,\n reject,\n {\n status: 404,\n config: config,\n },\n mockAdapter.delayResponse\n );\n }\n }\n}\n\nfunction getEffectiveDelay(adapter, handler) {\n var delayPerRequest;\n if (handler.length === 8) {\n delayPerRequest = handler[7];\n }\n return delayPerRequest ? delayPerRequest : adapter.delayResponse;\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 transformRequest(data) {\n if (\n utils.isArrayBuffer(data) ||\n utils.isBuffer(data) ||\n utils.isStream(data) ||\n utils.isBlob(data)\n ) {\n return data;\n }\n\n // Object and Array: returns a deep copy\n if (utils.isObjectOrArray(data)) {\n return JSON.parse(JSON.stringify(data));\n }\n\n // for primitives like string, undefined, null, number\n return data;\n}\n\nfunction makeResponse(result, config) {\n return {\n status: result[0],\n data: transformRequest(result[1]),\n headers: result[2],\n config: config,\n request: {\n responseURL: config.url,\n },\n };\n}\n\nfunction passThroughRequest (mockAdapter, resolve, reject, config) {\n // Axios v0.17 mutates the url to include the baseURL for non hostnames\n // but does not remove the baseURL from the config\n var baseURL = config.baseURL;\n if (config.baseURL && !/^https?:/.test(config.baseURL)) {\n baseURL = undefined;\n }\n\n // Axios pre 1.2\n if (typeof mockAdapter.originalAdapter === 'function') {\n return mockAdapter.originalAdapter(config).then(resolve, reject);\n }\n\n mockAdapter.axiosInstanceWithoutInterceptors(Object.assign({}, config, {\n baseURL: baseURL,\n // Use the original adapter, not the mock adapter\n adapter: mockAdapter.originalAdapter,\n // The request transformation runs on the original axios handler already\n transformRequest: [],\n transformResponse: []\n })).then(resolve, reject);\n}\n\nfunction handleRequest(mockAdapter, resolve, reject, config) {\n var url = config.url || \"\";\n // TODO we're not hitting this `if` in any of the tests, investigate\n if (\n config.baseURL &&\n url.substr(0, config.baseURL.length) === config.baseURL\n ) {\n url = url.slice(config.baseURL.length);\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 && config.headers.constructor.name === 'AxiosHeaders')\n ? Object.assign({}, config.headers.toJSON())\n : config.headers,\n config.baseURL\n );\n\n if (handler) {\n if (handler[6] === true) {\n utils.purgeIfReplyOnce(mockAdapter, handler);\n }\n\n if (handler.length === 2) {\n // passThrough handler\n passThroughRequest(mockAdapter, resolve, reject, config);\n } else if (typeof handler[3] !== \"function\") {\n utils.settle(\n resolve,\n reject,\n makeResponse(handler.slice(3), config),\n getEffectiveDelay(mockAdapter, handler)\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(\n resolve,\n reject,\n makeResponse(result, config),\n getEffectiveDelay(mockAdapter, handler)\n );\n } else {\n result.then(\n function (result) {\n if (result.config && result.status) {\n utils.settle(\n resolve,\n reject,\n makeResponse(\n [result.status, result.data, result.headers],\n result.config\n ),\n 0\n );\n } else {\n utils.settle(\n resolve,\n reject,\n makeResponse(result, config),\n getEffectiveDelay(mockAdapter, handler)\n );\n }\n },\n function (error) {\n if (mockAdapter.delayResponse > 0) {\n setTimeout(function () {\n reject(error);\n }, getEffectiveDelay(mockAdapter, handler));\n } else {\n reject(error);\n }\n }\n );\n }\n }\n } else {\n // handler not found\n switch (mockAdapter.onNoMatch) {\n case \"passthrough\":\n passThroughRequest(mockAdapter, resolve, reject, config);\n break;\n case \"throwException\":\n throw utils.createCouldNotFindMockError(config);\n default:\n utils.settle(\n resolve,\n reject,\n {\n status: 404,\n config: config,\n },\n mockAdapter.delayResponse\n );\n }\n }\n}\n\nfunction getEffectiveDelay(adapter, handler) {\n var delayPerRequest = handler[7];\n return typeof delayPerRequest === 'number' ? delayPerRequest : adapter.delayResponse;\n}\n\nmodule.exports = handleRequest;\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/handle_request.js?");

@@ -62,3 +62,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 replyWithDelay(delay, code, response, headers) {\n var handler = [matcher, body, requestHeaders, code, response, headers, false, delay];\n addHandler(method, _this.handlers, handler);\n return _this;\n }\n\n function withDelayInMs(delay) {\n return function (code, response, headers) {\n replyWithDelay(delay, code, response, headers);\n };\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 withDelayInMs: withDelayInMs,\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?");
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\nvar methodsWithConfigsAsSecondArg = [\"any\", \"get\", \"delete\", \"head\", \"options\"];\nfunction convertDataAndConfigToConfig (method, data, config) {\n if (methodsWithConfigsAsSecondArg.includes(method)) {\n return validateconfig(method, data || {});\n } else {\n return validateconfig(method, Object.assign({}, config, { data: data }));\n }\n}\n\nvar allowedConfigProperties = ['headers', 'params', 'data'];\nfunction validateconfig (method, config) {\n for (var key in config) {\n if (!allowedConfigProperties.includes(key)) {\n throw new Error(\n 'Invalid config property ' +\n JSON.stringify(key) +\n ' provided to ' +\n toMethodName(method) +\n '. Config: ' +\n JSON.stringify(config)\n );\n }\n }\n\n return config;\n}\n\nfunction toMethodName (method) {\n return \"on\" + method.charAt(0).toUpperCase() + method.slice(1);\n}\n\nVERBS.concat(\"any\").forEach(function (method) {\n MockAdapter.prototype[toMethodName(method)] = function (matcher, data, config) {\n var _this = this;\n var matcher = matcher === undefined ? /.*/ : matcher;\n var delay;\n var paramsAndBody = convertDataAndConfigToConfig(method, data, config);\n\n function reply(code, response, headers) {\n var handler = [matcher, paramsAndBody, paramsAndBody.headers, code, response, headers, false, delay];\n addHandler(method, _this.handlers, handler);\n return _this;\n }\n\n function withDelayInMs(_delay) {\n delay = _delay;\n var respond = requestApi.reply.bind(requestApi);\n Object.assign(respond, requestApi);\n return respond;\n }\n\n function replyOnce(code, response, headers) {\n var handler = [matcher, paramsAndBody, paramsAndBody.headers, code, response, headers, true, delay];\n addHandler(method, _this.handlers, handler);\n return _this;\n }\n\n var requestApi = {\n reply: reply,\n\n replyOnce: replyOnce,\n\n withDelayInMs: withDelayInMs,\n\n passThrough: function passThrough() {\n var handler = [matcher, paramsAndBody];\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 return requestApi;\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[6] === true;\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 // handler[6] !== true indicates that a handler only runs once.\n // It's supported to register muliple ones like that without\n // overwriting the previous one.\n if (indexOfExistingHandler > -1 && handler[6] !== true) {\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?");

@@ -84,3 +84,3 @@ /***/ }),

"use strict";
eval("\n\nvar axios = __webpack_require__(/*! axios */ \"axios\");\nvar isEqual = __webpack_require__(/*! fast-deep-equal */ \"./node_modules/fast-deep-equal/index.js\");\nvar isBuffer = __webpack_require__(/*! is-buffer */ \"./node_modules/is-buffer/index.js\");\nvar isBlob = __webpack_require__(/*! ./is_blob */ \"./src/is_blob.js\");\nvar toString = Object.prototype.toString;\n\nfunction find(array, predicate) {\n var length = array.length;\n for (var i = 0; i < length; i++) {\n var value = array[i];\n if (predicate(value)) return value;\n }\n}\n\nfunction isFunction(val) {\n return toString.call(val) === \"[object Function]\";\n}\n\nfunction isObjectOrArray(val) {\n return val !== null && typeof val === \"object\";\n}\n\nfunction isStream(val) {\n return isObjectOrArray(val) && isFunction(val.pipe);\n}\n\nfunction isArrayBuffer(val) {\n return toString.call(val) === \"[object ArrayBuffer]\";\n}\n\nfunction combineUrls(baseURL, url) {\n if (baseURL) {\n return baseURL.replace(/\\/+$/, \"\") + \"/\" + url.replace(/^\\/+/, \"\");\n }\n\n return url;\n}\n\nfunction findHandler(\n handlers,\n method,\n url,\n body,\n parameters,\n headers,\n baseURL\n) {\n return find(handlers[method.toLowerCase()], function (handler) {\n if (typeof handler[0] === \"string\") {\n return (\n (isUrlMatching(url, handler[0]) ||\n isUrlMatching(combineUrls(baseURL, url), handler[0])) &&\n isBodyOrParametersMatching(method, body, parameters, handler[1]) &&\n isObjectMatching(headers, handler[2])\n );\n } else if (handler[0] instanceof RegExp) {\n return (\n (handler[0].test(url) || handler[0].test(combineUrls(baseURL, url))) &&\n isBodyOrParametersMatching(method, body, parameters, handler[1]) &&\n isObjectMatching(headers, handler[2])\n );\n }\n });\n}\n\nfunction isUrlMatching(url, required) {\n var noSlashUrl = url[0] === \"/\" ? url.substr(1) : url;\n var noSlashRequired = required[0] === \"/\" ? required.substr(1) : required;\n return noSlashUrl === noSlashRequired;\n}\n\nfunction isBodyOrParametersMatching(method, body, parameters, required) {\n var allowedParamsMethods = [\"delete\", \"get\", \"head\", \"options\"];\n if (allowedParamsMethods.indexOf(method.toLowerCase()) >= 0) {\n var data = required ? required.data : undefined;\n var params = required ? required.params : undefined;\n return isObjectMatching(parameters, params) && isBodyMatching(body, data);\n } else {\n return isBodyMatching(body, required);\n }\n}\n\nfunction isObjectMatching(actual, expected) {\n if (expected === undefined) return true;\n if (typeof expected.asymmetricMatch === \"function\") {\n return expected.asymmetricMatch(actual);\n }\n return isEqual(actual, expected);\n}\n\nfunction isBodyMatching(body, requiredBody) {\n if (requiredBody === undefined) {\n return true;\n }\n var parsedBody;\n try {\n parsedBody = JSON.parse(body);\n } catch (e) {}\n\n return isObjectMatching(parsedBody ? parsedBody : body, requiredBody);\n}\n\nfunction purgeIfReplyOnce(mock, handler) {\n Object.keys(mock.handlers).forEach(function (key) {\n var index = mock.handlers[key].indexOf(handler);\n if (index > -1) {\n mock.handlers[key].splice(index, 1);\n }\n });\n}\n\nfunction settle(resolve, reject, response, delay) {\n if (delay > 0) {\n setTimeout(settle, delay, resolve, reject, response);\n return;\n }\n\n if (\n !response.config.validateStatus ||\n response.config.validateStatus(response.status)\n ) {\n resolve(response);\n } else {\n reject(\n createAxiosError(\n \"Request failed with status code \" + response.status,\n response.config,\n response\n )\n );\n }\n}\n\nfunction createAxiosError(message, config, response, code) {\n // axios v0.27.0+ defines AxiosError as constructor\n if (typeof axios.AxiosError === \"function\") {\n return axios.AxiosError.from(new Error(message), code, config, null, response);\n }\n\n // handling for axios v0.26.1 and below\n var error = new Error(message);\n error.isAxiosError = true;\n error.config = config;\n if (response !== undefined) {\n error.response = response;\n }\n if (code !== undefined) {\n error.code = code;\n }\n\n error.toJSON = function toJSON() {\n return {\n // Standard\n message: this.message,\n name: this.name,\n // Microsoft\n description: this.description,\n number: this.number,\n // Mozilla\n fileName: this.fileName,\n lineNumber: this.lineNumber,\n columnNumber: this.columnNumber,\n stack: this.stack,\n // Axios\n config: this.config,\n code: this.code,\n };\n };\n return error;\n}\n\nfunction createCouldNotFindMockError(config) {\n var message =\n \"Could not find mock for: \\n\" +\n JSON.stringify(config, [\"method\", \"url\"], 2);\n var error = new Error(message);\n error.isCouldNotFindMockError = true;\n error.url = config.url;\n error.method = config.method;\n return error;\n}\n\nmodule.exports = {\n find: find,\n findHandler: findHandler,\n purgeIfReplyOnce: purgeIfReplyOnce,\n settle: settle,\n isStream: isStream,\n isArrayBuffer: isArrayBuffer,\n isFunction: isFunction,\n isObjectOrArray: isObjectOrArray,\n isBuffer: isBuffer,\n isBlob: isBlob,\n isBodyOrParametersMatching: isBodyOrParametersMatching,\n isEqual: isEqual,\n createAxiosError: createAxiosError,\n createCouldNotFindMockError: createCouldNotFindMockError,\n};\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/utils.js?");
eval("\n\nvar axios = __webpack_require__(/*! axios */ \"axios\");\nvar isEqual = __webpack_require__(/*! fast-deep-equal */ \"./node_modules/fast-deep-equal/index.js\");\nvar isBuffer = __webpack_require__(/*! is-buffer */ \"./node_modules/is-buffer/index.js\");\nvar isBlob = __webpack_require__(/*! ./is_blob */ \"./src/is_blob.js\");\nvar toString = Object.prototype.toString;\n\nfunction find(array, predicate) {\n var length = array.length;\n for (var i = 0; i < length; i++) {\n var value = array[i];\n if (predicate(value)) return value;\n }\n}\n\nfunction isFunction(val) {\n return toString.call(val) === \"[object Function]\";\n}\n\nfunction isObjectOrArray(val) {\n return val !== null && typeof val === \"object\";\n}\n\nfunction isStream(val) {\n return isObjectOrArray(val) && isFunction(val.pipe);\n}\n\nfunction isArrayBuffer(val) {\n return toString.call(val) === \"[object ArrayBuffer]\";\n}\n\nfunction combineUrls(baseURL, url) {\n if (baseURL) {\n return baseURL.replace(/\\/+$/, \"\") + \"/\" + url.replace(/^\\/+/, \"\");\n }\n\n return url;\n}\n\nfunction findHandler(\n handlers,\n method,\n url,\n body,\n parameters,\n headers,\n baseURL\n) {\n return find(handlers[method.toLowerCase()], function (handler) {\n var matchesUrl = false;\n if (typeof handler[0] === \"string\") {\n matchesUrl = isUrlMatching(url, handler[0]) ||\n isUrlMatching(combineUrls(baseURL, url), handler[0]);\n } else if (handler[0] instanceof RegExp) {\n matchesUrl = handler[0].test(url) ||\n handler[0].test(combineUrls(baseURL, url));\n }\n\n return matchesUrl &&\n isBodyOrParametersMatching(body, parameters, handler[1]) &&\n isObjectMatching(headers, handler[2]);\n });\n}\n\nfunction isUrlMatching(url, required) {\n var noSlashUrl = url[0] === \"/\" ? url.substr(1) : url;\n var noSlashRequired = required[0] === \"/\" ? required.substr(1) : required;\n return noSlashUrl === noSlashRequired;\n}\n\nfunction isBodyOrParametersMatching(body, parameters, required) {\n return isObjectMatching(parameters, required && required.params) &&\n isBodyMatching(body, required && required.data);\n}\n\nfunction isObjectMatching(actual, expected) {\n if (expected === undefined) return true;\n if (typeof expected.asymmetricMatch === \"function\") {\n return expected.asymmetricMatch(actual);\n }\n return isEqual(actual, expected);\n}\n\nfunction isBodyMatching(body, requiredBody) {\n if (requiredBody === undefined) {\n return true;\n }\n var parsedBody;\n try {\n parsedBody = JSON.parse(body);\n } catch (e) {}\n\n return isObjectMatching(parsedBody ? parsedBody : body, requiredBody);\n}\n\nfunction purgeIfReplyOnce(mock, handler) {\n Object.keys(mock.handlers).forEach(function (key) {\n var index = mock.handlers[key].indexOf(handler);\n if (index > -1) {\n mock.handlers[key].splice(index, 1);\n }\n });\n}\n\nfunction settle(resolve, reject, response, delay) {\n if (delay > 0) {\n setTimeout(settle, delay, resolve, reject, response);\n return;\n }\n\n if (\n !response.config.validateStatus ||\n response.config.validateStatus(response.status)\n ) {\n resolve(response);\n } else {\n reject(\n createAxiosError(\n \"Request failed with status code \" + response.status,\n response.config,\n response\n )\n );\n }\n}\n\nfunction createAxiosError(message, config, response, code) {\n // axios v0.27.0+ defines AxiosError as constructor\n if (typeof axios.AxiosError === \"function\") {\n return axios.AxiosError.from(new Error(message), code, config, null, response);\n }\n\n // handling for axios v0.26.1 and below\n var error = new Error(message);\n error.isAxiosError = true;\n error.config = config;\n if (response !== undefined) {\n error.response = response;\n }\n if (code !== undefined) {\n error.code = code;\n }\n\n error.toJSON = function toJSON() {\n return {\n // Standard\n message: this.message,\n name: this.name,\n // Microsoft\n description: this.description,\n number: this.number,\n // Mozilla\n fileName: this.fileName,\n lineNumber: this.lineNumber,\n columnNumber: this.columnNumber,\n stack: this.stack,\n // Axios\n config: this.config,\n code: this.code,\n };\n };\n return error;\n}\n\nfunction createCouldNotFindMockError(config) {\n var message =\n \"Could not find mock for: \\n\" +\n JSON.stringify({\n method: config.method,\n url: config.url,\n params: config.params,\n headers: config.headers\n }, null, 2);\n var error = new Error(message);\n error.isCouldNotFindMockError = true;\n error.url = config.url;\n error.method = config.method;\n return error;\n}\n\nmodule.exports = {\n find: find,\n findHandler: findHandler,\n purgeIfReplyOnce: purgeIfReplyOnce,\n settle: settle,\n isStream: isStream,\n isArrayBuffer: isArrayBuffer,\n isFunction: isFunction,\n isObjectOrArray: isObjectOrArray,\n isBuffer: isBuffer,\n isBlob: isBlob,\n isBodyOrParametersMatching: isBodyOrParametersMatching,\n isEqual: isEqual,\n createAxiosError: createAxiosError,\n createCouldNotFindMockError: createCouldNotFindMockError,\n};\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/utils.js?");

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

/*! For license information please see axios-mock-adapter.min.js.LICENSE.txt */
!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)}(self,(t=>{return e={63:t=>{"use strict";t.exports=function t(e,r){if(e===r)return!0;if(e&&r&&"object"==typeof e&&"object"==typeof r){if(e.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(e)){if((n=e.length)!=r.length)return!1;for(o=n;0!=o--;)if(!t(e[o],r[o]))return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();if((n=(i=Object.keys(e)).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(!t(e[s],r[s]))return!1}return!0}return e!=e&&r!=r}},738:t=>{t.exports=function(t){return null!=t&&null!=t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}},141:(t,e,r)=>{"use strict";var n=r(555);function o(t,e){return{status:t[0],data:(r=t[1],n.isArrayBuffer(r)||n.isBuffer(r)||n.isStream(r)||n.isBlob(r)?r:n.isObjectOrArray(r)?JSON.parse(JSON.stringify(r)):r),headers:t[2],config:e,request:{responseURL:e.url}};var r}function i(t,e,r,n){var o=n.baseURL;if(n.baseURL&&!/^https?:/.test(n.baseURL)&&(o=void 0),"function"==typeof t.originalAdapter)return t.originalAdapter(n).then(e,r);t.axiosInstanceWithoutInterceptors(Object.assign({},n,{baseURL:o,adapter:t.originalAdapter,transformRequest:[],transformResponse:[]})).then(e,r)}function s(t,e){var r;return 8===e.length&&(r=e[7]),r||t.delayResponse}t.exports=function(t,e,r,a){var u=a.url||"";a.baseURL&&u.substr(0,a.baseURL.length)===a.baseURL&&(u=u.slice(a.baseURL.length)),delete a.adapter,t.history[a.method].push(a);var c=n.findHandler(t.handlers,a.method,u,a.data,a.params,a.headers&&"AxiosHeaders"===a.headers.constructor.name?Object.assign({},a.headers):a.headers,a.baseURL);if(c)if(7===c.length&&n.purgeIfReplyOnce(t,c),2===c.length)i(t,e,r,a);else if("function"!=typeof c[3])n.settle(e,r,o(c.slice(3),a),s(t,c));else{var f=c[3](a);"function"!=typeof f.then?n.settle(e,r,o(f,a),s(t,c)):f.then((function(i){i.config&&i.status?n.settle(e,r,o([i.status,i.data,i.headers],i.config),0):n.settle(e,r,o(i,a),s(t,c))}),(function(e){t.delayResponse>0?setTimeout((function(){r(e)}),s(t,c)):r(e)}))}else switch(t.onNoMatch){case"passthrough":i(t,e,r,a);break;case"throwException":throw n.createCouldNotFindMockError(a);default:n.settle(e,r,{status:404,config:a},t.delayResponse)}}},138:(t,e,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(t,e){return t[e]=[],t}),{})}function a(){u.call(this),c.call(this)}function u(){this.handlers=s()}function c(){this.history=s()}function f(t,e){if(a.call(this),!t)throw new Error("Please provide an instance of axios to mock");this.axiosInstance=t,this.axiosInstanceWithoutInterceptors=t.create?t.create():void 0,this.originalAdapter=t.defaults.adapter,this.delayResponse=e&&e.delayResponse>0?e.delayResponse:null,this.onNoMatch=e&&e.onNoMatch||null,t.defaults.adapter=this.adapter.call(this)}function l(t,e,r){if("any"===t)i.forEach((function(t){e[t].push(r)}));else{var n=function(t,e,r){for(var n=-1,i=0;i<e[t].length;i+=1){var s=e[t][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}(t,e,r);n>-1&&r.length<7?e[t].splice(n,1,r):e[t].push(r)}}f.prototype.adapter=function(){return function(t){var e=this;return new Promise((function(r,o){n(e,r,o,t)}))}.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(t){var e="on"+t.charAt(0).toUpperCase()+t.slice(1);f.prototype[e]=function(e,r,n){var i=this;function s(o,s,a){var u=[e,r,n,o,s,a];return l(t,i.handlers,u),i}function a(o,s,a){var u=[e,r,n,o,s,a,!0];return l(t,i.handlers,u),i}return e=void 0===e?/.*/:e,{reply:s,replyOnce:a,withDelayInMs:function(o){return function(s,a,u){!function(o,s,a,u){var c=[e,r,n,s,a,u,!1,o];l(t,i.handlers,c)}(o,s,a,u)}},passThrough:function(){var n=[e,r];return l(t,i.handlers,n),i},abortRequest:function(){return s((function(t){var e=o.createAxiosError("Request aborted",t,void 0,"ECONNABORTED");return Promise.reject(e)}))},abortRequestOnce:function(){return a((function(t){var e=o.createAxiosError("Request aborted",t,void 0,"ECONNABORTED");return Promise.reject(e)}))},networkError:function(){return s((function(t){var e=o.createAxiosError("Network Error",t);return Promise.reject(e)}))},networkErrorOnce:function(){return a((function(t){var e=o.createAxiosError("Network Error",t);return Promise.reject(e)}))},timeout:function(){return s((function(t){var e=o.createAxiosError(t.timeoutErrorMessage||"timeout of "+t.timeout+"ms exceeded",t,void 0,t.transitional&&t.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED");return Promise.reject(e)}))},timeoutOnce:function(){return a((function(t){var e=o.createAxiosError(t.timeoutErrorMessage||"timeout of "+t.timeout+"ms exceeded",t,void 0,t.transitional&&t.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED");return Promise.reject(e)}))}}}})),t.exports=f,t.exports.default=f},376:t=>{t.exports=function(t){return"undefined"!=typeof Blob&&(t instanceof Blob||"[object Blob]"===Object.prototype.toString.call(t))}},555:(t,e,r)=>{"use strict";var n=r(300),o=r(63),i=r(738),s=r(376),a=Object.prototype.toString;function u(t,e){for(var r=t.length,n=0;n<r;n++){var o=t[n];if(e(o))return o}}function c(t){return"[object Function]"===a.call(t)}function f(t){return null!==t&&"object"==typeof t}function l(t,e){return t?t.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,""):e}function p(t,e){return("/"===t[0]?t.substr(1):t)===("/"===e[0]?e.substr(1):e)}function d(t,e,r,n){if(["delete","get","head","options"].indexOf(t.toLowerCase())>=0){var o=n?n.data:void 0;return h(r,n?n.params:void 0)&&y(e,o)}return y(e,n)}function h(t,e){return void 0===e||("function"==typeof e.asymmetricMatch?e.asymmetricMatch(t):o(t,e))}function y(t,e){if(void 0===e)return!0;var r;try{r=JSON.parse(t)}catch(t){}return h(r||t,e)}function v(t,e,r,o){if("function"==typeof n.AxiosError)return n.AxiosError.from(new Error(t),o,e,null,r);var i=new Error(t);return i.isAxiosError=!0,i.config=e,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}t.exports={find:u,findHandler:function(t,e,r,n,o,i,s){return u(t[e.toLowerCase()],(function(t){return"string"==typeof t[0]?(p(r,t[0])||p(l(s,r),t[0]))&&d(e,n,o,t[1])&&h(i,t[2]):t[0]instanceof RegExp?(t[0].test(r)||t[0].test(l(s,r)))&&d(e,n,o,t[1])&&h(i,t[2]):void 0}))},purgeIfReplyOnce:function(t,e){Object.keys(t.handlers).forEach((function(r){var n=t.handlers[r].indexOf(e);n>-1&&t.handlers[r].splice(n,1)}))},settle:function t(e,r,n,o){o>0?setTimeout(t,o,e,r,n):!n.config.validateStatus||n.config.validateStatus(n.status)?e(n):r(v("Request failed with status code "+n.status,n.config,n))},isStream:function(t){return f(t)&&c(t.pipe)},isArrayBuffer:function(t){return"[object ArrayBuffer]"===a.call(t)},isFunction:c,isObjectOrArray:f,isBuffer:i,isBlob:s,isBodyOrParametersMatching:d,isEqual:o,createAxiosError:v,createCouldNotFindMockError:function(t){var e="Could not find mock for: \n"+JSON.stringify(t,["method","url"],2),r=new Error(e);return r.isCouldNotFindMockError=!0,r.url=t.url,r.method=t.method,r}}},300:e=>{"use strict";e.exports=t}},r={},function t(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return e[n](i,i.exports,t),i.exports}(138);var e,r}));
!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)}(self,(t=>{return e={17:t=>{"use strict";t.exports=function t(e,r){if(e===r)return!0;if(e&&r&&"object"==typeof e&&"object"==typeof r){if(e.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(e)){if((n=e.length)!=r.length)return!1;for(o=n;0!=o--;)if(!t(e[o],r[o]))return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();if((n=(i=Object.keys(e)).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(!t(e[s],r[s]))return!1}return!0}return e!=e&&r!=r}},206:t=>{t.exports=function(t){return null!=t&&null!=t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}},938:(t,e,r)=>{"use strict";var n=r(413);function o(t,e){return{status:t[0],data:(r=t[1],n.isArrayBuffer(r)||n.isBuffer(r)||n.isStream(r)||n.isBlob(r)?r:n.isObjectOrArray(r)?JSON.parse(JSON.stringify(r)):r),headers:t[2],config:e,request:{responseURL:e.url}};var r}function i(t,e,r,n){var o=n.baseURL;if(n.baseURL&&!/^https?:/.test(n.baseURL)&&(o=void 0),"function"==typeof t.originalAdapter)return t.originalAdapter(n).then(e,r);t.axiosInstanceWithoutInterceptors(Object.assign({},n,{baseURL:o,adapter:t.originalAdapter,transformRequest:[],transformResponse:[]})).then(e,r)}function s(t,e){var r=e[7];return"number"==typeof r?r:t.delayResponse}t.exports=function(t,e,r,a){var u=a.url||"";a.baseURL&&u.substr(0,a.baseURL.length)===a.baseURL&&(u=u.slice(a.baseURL.length)),delete a.adapter,t.history[a.method].push(a);var c=n.findHandler(t.handlers,a.method,u,a.data,a.params,a.headers&&"AxiosHeaders"===a.headers.constructor.name?Object.assign({},a.headers.toJSON()):a.headers,a.baseURL);if(c)if(!0===c[6]&&n.purgeIfReplyOnce(t,c),2===c.length)i(t,e,r,a);else if("function"!=typeof c[3])n.settle(e,r,o(c.slice(3),a),s(t,c));else{var f=c[3](a);"function"!=typeof f.then?n.settle(e,r,o(f,a),s(t,c)):f.then((function(i){i.config&&i.status?n.settle(e,r,o([i.status,i.data,i.headers],i.config),0):n.settle(e,r,o(i,a),s(t,c))}),(function(e){t.delayResponse>0?setTimeout((function(){r(e)}),s(t,c)):r(e)}))}else switch(t.onNoMatch){case"passthrough":i(t,e,r,a);break;case"throwException":throw n.createCouldNotFindMockError(a);default:n.settle(e,r,{status:404,config:a},t.delayResponse)}}},44:(t,e,r)=>{"use strict";var n=r(938),o=r(413),i=["get","post","head","delete","patch","put","options","list","link","unlink"];function s(){return i.reduce((function(t,e){return t[e]=[],t}),{})}function a(){u.call(this),c.call(this)}function u(){this.handlers=s()}function c(){this.history=s()}function f(t,e){if(a.call(this),!t)throw new Error("Please provide an instance of axios to mock");this.axiosInstance=t,this.axiosInstanceWithoutInterceptors=t.create?t.create():void 0,this.originalAdapter=t.defaults.adapter,this.delayResponse=e&&e.delayResponse>0?e.delayResponse:null,this.onNoMatch=e&&e.onNoMatch||null,t.defaults.adapter=this.adapter.call(this)}f.prototype.adapter=function(){return function(t){var e=this;return new Promise((function(r,o){n(e,r,o,t)}))}.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;var l=["any","get","delete","head","options"],p=["headers","params","data"];function d(t,e){for(var r in e)if(!p.includes(r))throw new Error("Invalid config property "+JSON.stringify(r)+" provided to "+h(t)+". Config: "+JSON.stringify(e));return e}function h(t){return"on"+t.charAt(0).toUpperCase()+t.slice(1)}function y(t,e,r){if("any"===t)i.forEach((function(t){e[t].push(r)}));else{var n=function(t,e,r){for(var n=-1,i=0;i<e[t].length;i+=1){var s=e[t][i],a=!0===s[6];(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}(t,e,r);n>-1&&!0!==r[6]?e[t].splice(n,1,r):e[t].push(r)}}i.concat("any").forEach((function(t){f.prototype[h(t)]=function(e,r,n){var i,s=this,a=(e=void 0===e?/.*/:e,function(t,e,r){return l.includes(t)?d(t,e||{}):d(t,Object.assign({},r,{data:e}))}(t,r,n));function u(r,n,o){var u=[e,a,a.headers,r,n,o,!1,i];return y(t,s.handlers,u),s}function c(r,n,o){var u=[e,a,a.headers,r,n,o,!0,i];return y(t,s.handlers,u),s}var f={reply:u,replyOnce:c,withDelayInMs:function(t){i=t;var e=f.reply.bind(f);return Object.assign(e,f),e},passThrough:function(){var r=[e,a];return y(t,s.handlers,r),s},abortRequest:function(){return u((function(t){var e=o.createAxiosError("Request aborted",t,void 0,"ECONNABORTED");return Promise.reject(e)}))},abortRequestOnce:function(){return c((function(t){var e=o.createAxiosError("Request aborted",t,void 0,"ECONNABORTED");return Promise.reject(e)}))},networkError:function(){return u((function(t){var e=o.createAxiosError("Network Error",t);return Promise.reject(e)}))},networkErrorOnce:function(){return c((function(t){var e=o.createAxiosError("Network Error",t);return Promise.reject(e)}))},timeout:function(){return u((function(t){var e=o.createAxiosError(t.timeoutErrorMessage||"timeout of "+t.timeout+"ms exceeded",t,void 0,t.transitional&&t.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED");return Promise.reject(e)}))},timeoutOnce:function(){return c((function(t){var e=o.createAxiosError(t.timeoutErrorMessage||"timeout of "+t.timeout+"ms exceeded",t,void 0,t.transitional&&t.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED");return Promise.reject(e)}))}};return f}})),t.exports=f,t.exports.default=f},58:t=>{t.exports=function(t){return"undefined"!=typeof Blob&&(t instanceof Blob||"[object Blob]"===Object.prototype.toString.call(t))}},413:(t,e,r)=>{"use strict";var n=r(742),o=r(17),i=r(206),s=r(58),a=Object.prototype.toString;function u(t,e){for(var r=t.length,n=0;n<r;n++){var o=t[n];if(e(o))return o}}function c(t){return"[object Function]"===a.call(t)}function f(t){return null!==t&&"object"==typeof t}function l(t,e){return t?t.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,""):e}function p(t,e){return("/"===t[0]?t.substr(1):t)===("/"===e[0]?e.substr(1):e)}function d(t,e,r){return h(e,r&&r.params)&&function(t,e){if(void 0===e)return!0;var r;try{r=JSON.parse(t)}catch(t){}return h(r||t,e)}(t,r&&r.data)}function h(t,e){return void 0===e||("function"==typeof e.asymmetricMatch?e.asymmetricMatch(t):o(t,e))}function y(t,e,r,o){if("function"==typeof n.AxiosError)return n.AxiosError.from(new Error(t),o,e,null,r);var i=new Error(t);return i.isAxiosError=!0,i.config=e,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}t.exports={find:u,findHandler:function(t,e,r,n,o,i,s){return u(t[e.toLowerCase()],(function(t){var e=!1;return"string"==typeof t[0]?e=p(r,t[0])||p(l(s,r),t[0]):t[0]instanceof RegExp&&(e=t[0].test(r)||t[0].test(l(s,r))),e&&d(n,o,t[1])&&h(i,t[2])}))},purgeIfReplyOnce:function(t,e){Object.keys(t.handlers).forEach((function(r){var n=t.handlers[r].indexOf(e);n>-1&&t.handlers[r].splice(n,1)}))},settle:function t(e,r,n,o){o>0?setTimeout(t,o,e,r,n):!n.config.validateStatus||n.config.validateStatus(n.status)?e(n):r(y("Request failed with status code "+n.status,n.config,n))},isStream:function(t){return f(t)&&c(t.pipe)},isArrayBuffer:function(t){return"[object ArrayBuffer]"===a.call(t)},isFunction:c,isObjectOrArray:f,isBuffer:i,isBlob:s,isBodyOrParametersMatching:d,isEqual:o,createAxiosError:y,createCouldNotFindMockError:function(t){var e="Could not find mock for: \n"+JSON.stringify({method:t.method,url:t.url,params:t.params,headers:t.headers},null,2),r=new Error(e);return r.isCouldNotFindMockError=!0,r.url=t.url,r.method=t.method,r}}},742:e=>{"use strict";e.exports=t}},r={},function t(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return e[n](i,i.exports,t),i.exports}(44);var e,r}));
{
"name": "axios-mock-adapter",
"version": "1.22.0",
"version": "2.0.0",
"description": "Axios adapter that allows to easily mock requests",
"main": "src/index.js",
"scripts": {
"clean": "rimraf dist",
"test": "mocha && npm run test:bundlesize && npm run test:types",
"test:bundlesize": "npm run clean && npm run build:umd:min && bundlesize",
"clean": "node -e 'require(`fs`).rmSync(`./dist`, {recursive: true, force: true})'",
"test": "mocha && npm run clean && npm run build:umd:min && npm run test:types",
"test:coverage": "nyc --reporter=html --reporter=text-summary mocha",

@@ -45,13 +44,10 @@ "test:types": "tsc --project types",

"devDependencies": {
"axios": "^0.27.2",
"bundlesize": "^0.18.1",
"axios": "^1.7.3",
"chai": "^4.3.6",
"eslint": "^8.16.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"typescript": "^5.0.2",
"webpack": "^5.72.1",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.9.2"
"eslint": "^8.57.0",
"mocha": "^10.7.0",
"nyc": "^17.0.0",
"typescript": "^5.5.4",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4"
},

@@ -61,9 +57,3 @@ "dependencies": {

"is-buffer": "^2.0.5"
},
"bundlesize": [
{
"path": "./dist/axios-mock-adapter.min.js",
"maxSize": "3.0 kB"
}
]
}
}

@@ -229,5 +229,7 @@ # axios-mock-adapter

{ id: 1 },
expect.objectContaining({
Authorization: expect.stringMatching(/^Basic /),
})
{
headers: expect.objectContaining({
Authorization: expect.stringMatching(/^Basic /),
})
}
)

@@ -234,0 +236,0 @@ .reply(204);

@@ -79,3 +79,3 @@ "use strict";

(config.headers && config.headers.constructor.name === 'AxiosHeaders')
? Object.assign({}, config.headers)
? Object.assign({}, config.headers.toJSON())
: config.headers,

@@ -86,3 +86,3 @@ config.baseURL

if (handler) {
if (handler.length === 7) {
if (handler[6] === true) {
utils.purgeIfReplyOnce(mockAdapter, handler);

@@ -168,9 +168,6 @@ }

function getEffectiveDelay(adapter, handler) {
var delayPerRequest;
if (handler.length === 8) {
delayPerRequest = handler[7];
}
return delayPerRequest ? delayPerRequest : adapter.delayResponse;
var delayPerRequest = handler[7];
return typeof delayPerRequest === 'number' ? delayPerRequest : adapter.delayResponse;
}
module.exports = handleRequest;

@@ -82,10 +82,42 @@ "use strict";

var methodsWithConfigsAsSecondArg = ["any", "get", "delete", "head", "options"];
function convertDataAndConfigToConfig (method, data, config) {
if (methodsWithConfigsAsSecondArg.includes(method)) {
return validateconfig(method, data || {});
} else {
return validateconfig(method, Object.assign({}, config, { data: data }));
}
}
var allowedConfigProperties = ['headers', 'params', 'data'];
function validateconfig (method, config) {
for (var key in config) {
if (!allowedConfigProperties.includes(key)) {
throw new Error(
'Invalid config property ' +
JSON.stringify(key) +
' provided to ' +
toMethodName(method) +
'. Config: ' +
JSON.stringify(config)
);
}
}
return config;
}
function toMethodName (method) {
return "on" + method.charAt(0).toUpperCase() + method.slice(1);
}
VERBS.concat("any").forEach(function (method) {
var methodName = "on" + method.charAt(0).toUpperCase() + method.slice(1);
MockAdapter.prototype[methodName] = function (matcher, body, requestHeaders) {
MockAdapter.prototype[toMethodName(method)] = function (matcher, data, config) {
var _this = this;
var matcher = matcher === undefined ? /.*/ : matcher;
var delay;
var paramsAndBody = convertDataAndConfigToConfig(method, data, config);
function reply(code, response, headers) {
var handler = [matcher, body, requestHeaders, code, response, headers];
var handler = [matcher, paramsAndBody, paramsAndBody.headers, code, response, headers, false, delay];
addHandler(method, _this.handlers, handler);

@@ -95,24 +127,11 @@ return _this;

function replyWithDelay(delay, code, response, headers) {
var handler = [matcher, body, requestHeaders, code, response, headers, false, delay];
addHandler(method, _this.handlers, handler);
return _this;
function withDelayInMs(_delay) {
delay = _delay;
var respond = requestApi.reply.bind(requestApi);
Object.assign(respond, requestApi);
return respond;
}
function withDelayInMs(delay) {
return function (code, response, headers) {
replyWithDelay(delay, code, response, headers);
};
}
function replyOnce(code, response, headers) {
var handler = [
matcher,
body,
requestHeaders,
code,
response,
headers,
true,
];
var handler = [matcher, paramsAndBody, paramsAndBody.headers, code, response, headers, true, delay];
addHandler(method, _this.handlers, handler);

@@ -122,3 +141,3 @@ return _this;

return {
var requestApi = {
reply: reply,

@@ -131,3 +150,3 @@

passThrough: function passThrough() {
var handler = [matcher, body];
var handler = [matcher, paramsAndBody];
addHandler(method, _this.handlers, handler);

@@ -205,2 +224,4 @@ return _this;

};
return requestApi;
};

@@ -213,3 +234,3 @@ });

var item = handlers[method][i];
var isReplyOnce = item.length === 7;
var isReplyOnce = item[6] === true;
var comparePaths =

@@ -237,3 +258,6 @@ item[0] instanceof RegExp && handler[0] instanceof RegExp

var indexOfExistingHandler = findInHandlers(method, handlers, handler);
if (indexOfExistingHandler > -1 && handler.length < 7) {
// handler[6] !== true indicates that a handler only runs once.
// It's supported to register muliple ones like that without
// overwriting the previous one.
if (indexOfExistingHandler > -1 && handler[6] !== true) {
handlers[method].splice(indexOfExistingHandler, 1, handler);

@@ -240,0 +264,0 @@ } else {

@@ -51,16 +51,14 @@ "use strict";

return find(handlers[method.toLowerCase()], function (handler) {
var matchesUrl = false;
if (typeof handler[0] === "string") {
return (
(isUrlMatching(url, handler[0]) ||
isUrlMatching(combineUrls(baseURL, url), handler[0])) &&
isBodyOrParametersMatching(method, body, parameters, handler[1]) &&
isObjectMatching(headers, handler[2])
);
matchesUrl = isUrlMatching(url, handler[0]) ||
isUrlMatching(combineUrls(baseURL, url), handler[0]);
} else if (handler[0] instanceof RegExp) {
return (
(handler[0].test(url) || handler[0].test(combineUrls(baseURL, url))) &&
isBodyOrParametersMatching(method, body, parameters, handler[1]) &&
isObjectMatching(headers, handler[2])
);
matchesUrl = handler[0].test(url) ||
handler[0].test(combineUrls(baseURL, url));
}
return matchesUrl &&
isBodyOrParametersMatching(body, parameters, handler[1]) &&
isObjectMatching(headers, handler[2]);
});

@@ -75,11 +73,5 @@ }

function isBodyOrParametersMatching(method, body, parameters, required) {
var allowedParamsMethods = ["delete", "get", "head", "options"];
if (allowedParamsMethods.indexOf(method.toLowerCase()) >= 0) {
var data = required ? required.data : undefined;
var params = required ? required.params : undefined;
return isObjectMatching(parameters, params) && isBodyMatching(body, data);
} else {
return isBodyMatching(body, required);
}
function isBodyOrParametersMatching(body, parameters, required) {
return isObjectMatching(parameters, required && required.params) &&
isBodyMatching(body, required && required.data);
}

@@ -179,3 +171,8 @@

"Could not find mock for: \n" +
JSON.stringify(config, ["method", "url"], 2);
JSON.stringify({
method: config.method,
url: config.url,
params: config.params,
headers: config.headers
}, null, 2);
var error = new Error(message);

@@ -182,0 +179,0 @@ error.isCouldNotFindMockError = true;

@@ -15,2 +15,3 @@ import { AxiosAdapter, AxiosInstance, AxiosRequestConfig } from 'axios';

export interface RequestHandler {
withDelayInMs(delay: number): RequestHandler;
reply: ResponseSpecFunc;

@@ -37,7 +38,4 @@ replyOnce: ResponseSpecFunc;

interface RequestDataMatcher {
[index: string]: any;
params?: {
[index: string]: any;
};
interface ParamsMatcher {
[param: string]: any;
}

@@ -49,12 +47,24 @@

type UrlMatcher = string | RegExp;
type AsymmetricParamsMatcher = AsymmetricMatcher | ParamsMatcher;
type AsymmetricHeadersMatcher = AsymmetricMatcher | HeadersMatcher;
type AsymmetricRequestDataMatcher = AsymmetricMatcher | any;
type AsymmetricRequestDataMatcher = AsymmetricMatcher | RequestDataMatcher;
interface ConfigMatcher {
params?: AsymmetricParamsMatcher;
headers?: AsymmetricHeadersMatcher;
data?: AsymmetricRequestDataMatcher;
}
type RequestMatcherFunc = (
matcher?: string | RegExp,
body?: string | AsymmetricRequestDataMatcher,
headers?: AsymmetricHeadersMatcher
matcher?: UrlMatcher,
body?: AsymmetricRequestDataMatcher,
config?: ConfigMatcher
) => MockAdapter.RequestHandler;
type NoBodyRequestMatcherFunc = (
matcher?: UrlMatcher,
config?: ConfigMatcher
) => MockAdapter.RequestHandler;
declare class MockAdapter {

@@ -73,11 +83,11 @@ static default: typeof MockAdapter;

onGet: RequestMatcherFunc;
onAny: NoBodyRequestMatcherFunc;
onGet: NoBodyRequestMatcherFunc;
onDelete: NoBodyRequestMatcherFunc;
onHead: NoBodyRequestMatcherFunc;
onOptions: NoBodyRequestMatcherFunc;
onPost: RequestMatcherFunc;
onPut: RequestMatcherFunc;
onHead: RequestMatcherFunc;
onDelete: RequestMatcherFunc;
onPatch: RequestMatcherFunc;
onList: RequestMatcherFunc;
onOptions: RequestMatcherFunc;
onAny: RequestMatcherFunc;
onLink: RequestMatcherFunc;

@@ -84,0 +94,0 @@ onUnlink: RequestMatcherFunc;

@@ -78,14 +78,10 @@ import axios from 'axios';

namespace AllowsBodyMatcher {
mock.onGet('/foo', {
id: 4,
name: 'foo'
});
mock.onPost('/foo', {id: 4, name: 'foo'});
mock.onPut('/foo', {id: 4, name: 'foo'});
mock.onAny('/foo', {data: {id: 4, name: 'foo'}});
}
namespace AllowsParameterMatcher {
mock.onGet('/foo', {
params: {
searchText: 'John'
}
});
namespace AllowsParamsMatcher {
mock.onGet('/foo', {params: {searchText: 'John'}});
mock.onDelete('/foo', {params: {searchText: 'John'}});
}

@@ -129,2 +125,6 @@

namespace withDelayInMs {
mock.onGet().withDelayInMs(2000).reply(200, { data: 'foo' });
}
namespace AllowsFunctionReply {

@@ -131,0 +131,0 @@ mock.onGet().reply(config => {

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