axios-mock-shim
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -42,3 +42,3 @@ /* eslint-disable */ | ||
*/ | ||
function mockHandler({ method, svc, data }, mockReply) { | ||
function mockHandler({ method, svc, config }, mockReply) { | ||
const mock = this; | ||
@@ -56,3 +56,3 @@ // handler choose | ||
// config handling | ||
mock[`on${firstUp(method)}`](svc, data) | ||
mock[`on${firstUp(method)}`](svc, ...config) | ||
.reply.apply(mock, isFn(handler) ? [handler] : handler); | ||
@@ -89,4 +89,13 @@ } | ||
const parent = this; | ||
const { ReplyCache } = this; | ||
const { ReplyCache, $options } = this; | ||
const { snakifyData, beforeRequest } = $options; | ||
const methodUp = method.toUpperCase(); | ||
const cacheToken = stringify(method, svc, data); | ||
data = snakifyData ? snakifyKeys(data) : data; | ||
let configs = { | ||
method, | ||
svc, | ||
data, | ||
config: configHandler({ methodUp, beforeRequest, data }), | ||
}; | ||
// Return an object to define mock data & calling | ||
@@ -104,17 +113,10 @@ return { | ||
}, | ||
run: parent.runBuilder.apply(parent, [method, svc, data]), | ||
run: parent.runBuilder.apply(parent, [configs]), | ||
}; | ||
}, | ||
useMockRequest(method, svc, data = {}) { | ||
useMockRequest(configs) { | ||
const { method, svc, data } = configs; | ||
const { normalRequest, $adapter, ReplyCache, $options } = this; | ||
const { snakifyData, anyReply, beforeRequest } = $options; | ||
const methodUp = method.toUpperCase(); | ||
const { anyReply } = $options; | ||
const cacheToken = stringify(method, svc, data); | ||
data = snakifyData ? snakifyKeys(data) : data; | ||
let configs = { | ||
method, | ||
svc, | ||
data, | ||
config: configHandler({ methodUp, beforeRequest, data }), | ||
}; | ||
// with mockReply defined & not yet cached | ||
@@ -139,4 +141,3 @@ const hasCache = RequestCache.has(cacheToken); | ||
const { beforeResponse } = $options; | ||
const methodUp = method.toUpperCase(); | ||
if (!httpMethodList.has(methodUp)) | ||
if (!httpMethodList.has(method.toUpperCase())) | ||
return warn('Invalid http method', method); | ||
@@ -143,0 +144,0 @@ return $instance[method.toLowerCase()](svc, ...config).then(beforeResponse ? beforeResponse : (res) => res); |
{ | ||
"name": "axios-mock-shim", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "A plugin build for easily using axios-mock-adapter with axios", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19414
405