axios-mock-shim
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -102,6 +102,6 @@ /* eslint-disable */ | ||
const { $instance, $options } = this; | ||
const { beforeResponse, snakifyData } = $options; | ||
const { beforeRequest, beforeResponse, snakifyData } = $options; | ||
if (!httpMethodList.has(method.toUpperCase())) | ||
return warn('Invalid http method', method); | ||
return $instance({ | ||
const params = { | ||
method, | ||
@@ -112,4 +112,5 @@ url: svc, | ||
: 'data']: snakifyData ? snakifyKeys(data) : data, | ||
}).then(beforeResponse ? beforeResponse : (res) => res); | ||
}; | ||
return $instance(beforeRequest ? beforeRequest(params) : params).then(beforeResponse ? beforeResponse : (res) => res); | ||
}, | ||
}; |
{ | ||
"name": "axios-mock-shim", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "A plugin build for easily using axios-mock-adapter with axios", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -137,2 +137,4 @@ # Axios Mock Shim | ||
- Type: `boolean` | ||
Required to set whether using mock-adapter. no default value. | ||
@@ -143,7 +145,38 @@ | ||
- Type: `boolean` | ||
Whether snakify keys in params or data in request. | ||
### beforeRequest | ||
- Type: `Function` | ||
provide a way to dynamically inject some axios config each request, such as getting localStorage data into `header`. | ||
it will give you the default params to send to request. | ||
if this property is not set, it will use the default params to call | ||
> Be careful not to overwrite the `method`, `data` or `params` property here, or you may send a wrong request every request. | ||
```js | ||
const api = createAPIHandler(instance, { | ||
beforeRequest(params) { | ||
const TOKEN = localStorage.getItem('TOKEN'); | ||
return Object.assign(params, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'My-Token': TOKEN, | ||
}, | ||
}); | ||
}, | ||
}); | ||
``` | ||
### beforeResponse | ||
- Type: `Function` | ||
You can specify what to do before getting the response, eg. | ||
@@ -154,4 +187,4 @@ | ||
useMock: true, | ||
beforeResponse(res) { | ||
return camelizeKeys(res.data); | ||
beforeResponse(response) { | ||
return camelizeKeys(response.data); | ||
}, | ||
@@ -158,0 +191,0 @@ }); |
@@ -15,2 +15,3 @@ export interface MockAdapterOptions { | ||
anyReply?: any; | ||
beforeRequest?: Function; | ||
beforeResponse?: Function; | ||
@@ -17,0 +18,0 @@ snakifyData?: boolean; |
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
18185
368
244