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.4 to 1.0.5

45

dist/request.js

@@ -5,2 +5,3 @@ /* eslint-disable */

import { mockDefaultConfig, httpMethodList } from './config';
// Cache for whole page
const RequestCache = new Set();

@@ -48,7 +49,8 @@ /**

this.$adapter = null;
this.mockReply = null;
this.run = () => { };
this.ReplyCache = new Map();
this.runBuilder = () => { };
this.init();
}
AxiosRequest.prototype = {
use(...args) {
init() {
const { $instance } = this;

@@ -59,17 +61,25 @@ const { useMock } = this.$options;

}
// run will return a [Promise]
this.run = useMock
? () => this.useMockRequest(...args)
: () => this.normalRequest(...args);
return this;
// runBuilder return the correct method for run
this.runBuilder = useMock
? (...args) => () => this.useMockRequest(...args)
: (...args) => () => this.normalRequest(...args);
},
with(fn) {
const invalid = !isFn(fn) && !isArray(fn);
if (invalid)
return warn('reply invalid, should be type Function or Array', fn);
this.mockReply = fn;
return this;
use(method, svc, data = {}) {
const parent = this;
const { ReplyCache } = this;
const cacheToken = stringify(method, svc, data);
// Return an object to define mock data & calling
return {
with(fn) {
const invalid = !isFn(fn) && !isArray(fn);
if (invalid)
return warn('reply invalid, should be type Function or Array', fn);
ReplyCache.set(cacheToken, fn);
return this;
},
run: parent.runBuilder.apply(parent, [method, svc, data]),
};
},
useMockRequest(method, svc, data = {}) {
const { normalRequest, mockReply, $adapter } = this;
const { normalRequest, $adapter, ReplyCache } = this;
const cacheToken = stringify(method, svc, data);

@@ -80,4 +90,5 @@ // with mockReply defined & not yet cached

RequestCache.add(cacheToken);
if (mockReply) {
mockHandler.call($adapter, { method, svc, data }, mockReply);
// check if cache has the mock data
if (ReplyCache.has(cacheToken)) {
mockHandler.call($adapter, { method, svc, data }, ReplyCache.get(cacheToken));
}

@@ -84,0 +95,0 @@ else {

{
"name": "axios-mock-shim",
"version": "1.0.4",
"version": "1.0.5",
"description": "A plugin build for easily using axios-mock-adapter with axios",

@@ -5,0 +5,0 @@ "main": "./index.js",

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