Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

axios-mock-shim

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-mock-shim - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

7

dist/request.js

@@ -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;

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