New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fluffy-spoon/substitute

Package Overview
Dependencies
Maintainers
1
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluffy-spoon/substitute - npm Package Compare versions

Comparing version 1.117.0 to 1.118.0

69

dist/src/Arguments.js
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Argument = /** @class */ (function () {
function Argument(description, matchingFunction) {
class Argument {
constructor(description, matchingFunction) {
this.description = description;
this.matchingFunction = matchingFunction;
}
Argument.prototype.matches = function (arg) {
matches(arg) {
return this.matchingFunction(arg);
};
Argument.prototype.toString = function () {
}
toString() {
return this.description;
};
Argument.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
}
[Symbol.for('nodejs.util.inspect.custom')]() {
return this.description;
};
return Argument;
}());
}
}
exports.Argument = Argument;
var AllArguments = /** @class */ (function (_super) {
__extends(AllArguments, _super);
function AllArguments() {
return _super.call(this, '{all}', function () { return true; }) || this;
class AllArguments extends Argument {
constructor() {
super('{all}', () => true);
}
return AllArguments;
}(Argument));
}
exports.AllArguments = AllArguments;
var Arg = /** @class */ (function () {
function Arg() {
class Arg {
static all() {
return this._all = (this._all || new AllArguments());
}
Arg.all = function () {
return this._all = (this._all || new AllArguments());
};
Arg.any = function (type) {
var description = !type ? '{any arg}' : '{type ' + type + '}';
return new Argument(description, function (x) {
static any(type) {
const description = !type ? '{any arg}' : '{type ' + type + '}';
return new Argument(description, x => {
if (!type)

@@ -58,7 +40,7 @@ return true;

});
};
Arg.is = function (predicate) {
}
static is(predicate) {
return new Argument('{predicate ' + this.toStringify(predicate) + '}', predicate);
};
Arg.toStringify = function (obj) {
}
static toStringify(obj) {
if (typeof obj.inspect === 'function')

@@ -69,6 +51,5 @@ return obj.inspect();

return obj;
};
return Arg;
}());
}
}
exports.Arg = Arg;
//# sourceMappingURL=Arguments.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("util");
var InitialState_1 = require("./states/InitialState");
var Substitute_1 = require("./Substitute");
var Utilities_1 = require("./Utilities");
var SetPropertyState_1 = require("./states/SetPropertyState");
var SubstituteBase_1 = require("./SubstituteBase");
var Context = /** @class */ (function () {
function Context() {
var _this_1 = this;
const util_1 = require("util");
const InitialState_1 = require("./states/InitialState");
const Substitute_1 = require("./Substitute");
const Utilities_1 = require("./Utilities");
const SetPropertyState_1 = require("./states/SetPropertyState");
const SubstituteBase_1 = require("./SubstituteBase");
class Context {
constructor() {
this._initialState = new InitialState_1.InitialState();

@@ -16,26 +15,26 @@ this._setState = this._initialState;

this._proxy = new Proxy(SubstituteBase_1.SubstituteJS, {
apply: function (_target, _this, args) { return _this_1.apply(_target, _this, args); },
set: function (_target, property, value) { return (_this_1.set(_target, property, value), true); },
get: function (_target, property) { return _this_1._filterAndReturnProperty(_target, property, _this_1.get); }
apply: (_target, _this, args) => this.apply(_target, _this, args),
set: (_target, property, value) => (this.set(_target, property, value), true),
get: (_target, property) => this._filterAndReturnProperty(_target, property, this.get)
});
this._rootProxy = new Proxy(SubstituteBase_1.SubstituteJS, {
apply: function (_target, _this, args) { return _this_1.initialState.apply(_this_1, args); },
set: function (_target, property, value) { return (_this_1.initialState.set(_this_1, property, value), true); },
get: function (_target, property) { return _this_1._filterAndReturnProperty(_target, property, _this_1.rootGet); }
apply: (_target, _this, args) => this.initialState.apply(this, args),
set: (_target, property, value) => (this.initialState.set(this, property, value), true),
get: (_target, property) => this._filterAndReturnProperty(_target, property, this.rootGet)
});
this._receivedProxy = new Proxy(SubstituteBase_1.SubstituteJS, {
apply: function (_target, _this, args) { return _this_1._receivedState === void 0 ? void 0 : _this_1._receivedState.apply(_this_1, args); },
set: function (_target, property, value) { return (_this_1.set(_target, property, value), true); },
get: function (_target, property) {
var state = _this_1.initialState.getPropertyStates.find(function (getPropertyState) { return getPropertyState.property === property; });
apply: (_target, _this, args) => this._receivedState === void 0 ? void 0 : this._receivedState.apply(this, args),
set: (_target, property, value) => (this.set(_target, property, value), true),
get: (_target, property) => {
const state = this.initialState.getPropertyStates.find(getPropertyState => getPropertyState.property === property);
if (state === void 0)
return _this_1.handleNotFoundState(property);
return this.handleNotFoundState(property);
if (!state.functionState)
state.get(_this_1, property);
_this_1._receivedState = state;
return _this_1.receivedProxy;
state.get(this, property);
this._receivedState = state;
return this.receivedProxy;
}
});
}
Context.prototype._filterAndReturnProperty = function (target, property, defaultGet) {
_filterAndReturnProperty(target, property, defaultGet) {
switch (property) {

@@ -62,4 +61,4 @@ case 'constructor':

}
};
Context.prototype.handleNotFoundState = function (property) {
}
handleNotFoundState(property) {
if (this.initialState.hasExpectations && this.initialState.expectedCount !== null) {

@@ -70,13 +69,13 @@ this.initialState.assertCallCountMatchesExpectations([], 0, Utilities_1.Type.property, property, []);

throw SubstituteBase_1.SubstituteException.forPropertyNotMocked(property);
};
Context.prototype.rootGet = function (_target, property) {
}
rootGet(_target, property) {
return this.initialState.get(this, property);
};
Context.prototype.apply = function (_target, _this, args) {
}
apply(_target, _this, args) {
return this._getState.apply(this, args);
};
Context.prototype.set = function (_target, property, value) {
}
set(_target, property, value) {
return this._setState.set(this, property, value);
};
Context.prototype.get = function (_target, property) {
}
get(_target, property) {
if (property === Substitute_1.HandlerKey) {

@@ -86,46 +85,25 @@ return this;

return this._getState.get(this, property);
};
Object.defineProperty(Context.prototype, "proxy", {
get: function () {
return this._proxy;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Context.prototype, "rootProxy", {
get: function () {
return this._rootProxy;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Context.prototype, "receivedProxy", {
get: function () {
return this._receivedProxy;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Context.prototype, "initialState", {
get: function () {
return this._initialState;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Context.prototype, "state", {
set: function (state) {
if (this._setState === state)
return;
state instanceof SetPropertyState_1.SetPropertyState ?
this._setState = state : this._getState = state;
if (state.onSwitchedTo)
state.onSwitchedTo(this);
},
enumerable: true,
configurable: true
});
return Context;
}());
}
get proxy() {
return this._proxy;
}
get rootProxy() {
return this._rootProxy;
}
get receivedProxy() {
return this._receivedProxy;
}
get initialState() {
return this._initialState;
}
set state(state) {
if (this._setState === state)
return;
state instanceof SetPropertyState_1.SetPropertyState ?
this._setState = state : this._getState = state;
if (state.onSwitchedTo)
state.onSwitchedTo(this);
}
}
exports.Context = Context;
//# sourceMappingURL=Context.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Substitute_1 = require("./Substitute");
const Substitute_1 = require("./Substitute");
exports.Substitute = Substitute_1.Substitute;

@@ -5,0 +5,0 @@ var Arguments_1 = require("./Arguments");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Utilities_1 = require("../Utilities");
var SubstituteBase_1 = require("../SubstituteBase");
var FunctionState = /** @class */ (function () {
function FunctionState(_getPropertyState) {
const Utilities_1 = require("../Utilities");
const SubstituteBase_1 = require("../SubstituteBase");
class FunctionState {
constructor(_getPropertyState) {
this._getPropertyState = _getPropertyState;

@@ -13,28 +13,16 @@ this.returns = [];

}
Object.defineProperty(FunctionState.prototype, "calls", {
get: function () {
return this._calls;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FunctionState.prototype, "callCount", {
get: function () {
return this._calls.length;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FunctionState.prototype, "property", {
get: function () {
return this._getPropertyState.property;
},
enumerable: true,
configurable: true
});
FunctionState.prototype.getCallCount = function (args) {
return this._calls.reduce(function (count, cargs) { return Utilities_1.areArgumentArraysEqual(cargs, args) ? count + 1 : count; }, 0);
};
FunctionState.prototype.apply = function (context, args) {
var hasExpectations = context.initialState.hasExpectations;
get calls() {
return this._calls;
}
get callCount() {
return this._calls.length;
}
get property() {
return this._getPropertyState.property;
}
getCallCount(args) {
return this._calls.reduce((count, cargs) => Utilities_1.areArgumentArraysEqual(cargs, args) ? count + 1 : count, 0);
}
apply(context, args) {
const hasExpectations = context.initialState.hasExpectations;
this._lastArgs = args;

@@ -47,3 +35,3 @@ context.initialState.assertCallCountMatchesExpectations(this._calls, this.getCallCount(args), Utilities_1.Type.method, this.property, args);

if (this.mimicks.length > 0) {
var mimicks = this.mimicks.find(function (mimick) { return Utilities_1.areArgumentArraysEqual(mimick.args, args); });
const mimicks = this.mimicks.find(mimick => Utilities_1.areArgumentArraysEqual(mimick.args, args));
if (mimicks !== void 0)

@@ -53,3 +41,3 @@ return mimicks.mimickFunction.apply(mimicks.mimickFunction, args);

if (this.throws.length > 0) {
var possibleThrow = this.throws.find(function (throws) { return Utilities_1.areArgumentArraysEqual(throws.args, args); });
const possibleThrow = this.throws.find(throws => Utilities_1.areArgumentArraysEqual(throws.args, args));
if (possibleThrow !== void 0)

@@ -60,5 +48,5 @@ throw possibleThrow.throwFunction;

return context.proxy;
var returns = this.returns.find(function (r) { return Utilities_1.areArgumentArraysEqual(r.args, args); });
const returns = this.returns.find(r => Utilities_1.areArgumentArraysEqual(r.args, args));
if (returns) {
var returnValues = returns.returnValues;
const returnValues = returns.returnValues;
if (returnValues.length === 1) {

@@ -75,19 +63,18 @@ return returnValues[0];

return context.proxy;
};
FunctionState.prototype.set = function (context, property, value) {
};
FunctionState.prototype.get = function (context, property) {
var _this = this;
}
set(context, property, value) {
}
get(context, property) {
if (property === 'then')
return void 0;
if (property === Utilities_1.SubstituteMethods.mimicks) {
return function (input) {
if (!_this._lastArgs) {
return (input) => {
if (!this._lastArgs) {
throw SubstituteBase_1.SubstituteException.generic('Eh, there\'s a bug, no args recorded for this mimicks :/');
}
_this.mimicks.push({
args: _this._lastArgs,
this.mimicks.push({
args: this._lastArgs,
mimickFunction: input
});
_this._calls.pop();
this._calls.pop();
context.state = context.initialState;

@@ -97,11 +84,11 @@ };

if (property === Utilities_1.SubstituteMethods.throws) {
return function (input) {
if (!_this._lastArgs) {
return (input) => {
if (!this._lastArgs) {
throw SubstituteBase_1.SubstituteException.generic('Eh, there\'s a bug, no args recorded for this throw :/');
}
_this.throws.push({
args: _this._lastArgs,
this.throws.push({
args: this._lastArgs,
throwFunction: input
});
_this._calls.pop();
this._calls.pop();
context.state = context.initialState;

@@ -113,11 +100,7 @@ };

|| property === Utilities_1.SubstituteMethods.rejects) {
return function () {
var returns = [];
for (var _i = 0; _i < arguments.length; _i++) {
returns[_i] = arguments[_i];
}
if (!_this._lastArgs) {
return (...returns) => {
if (!this._lastArgs) {
throw SubstituteBase_1.SubstituteException.generic('Eh, there\'s a bug, no args recorded for this return :/');
}
var returnMock = { returnIndex: 0, args: _this._lastArgs };
const returnMock = { returnIndex: 0, args: this._lastArgs };
switch (property) {

@@ -128,11 +111,11 @@ case Utilities_1.SubstituteMethods.returns:

case Utilities_1.SubstituteMethods.resolves:
returnMock.returnValues = returns.map(function (value) { return Promise.resolve(value); });
returnMock.returnValues = returns.map(value => Promise.resolve(value));
break;
case Utilities_1.SubstituteMethods.rejects:
returnMock.returnValues = returns.map(function (value) { return Promise.reject(value); });
returnMock.returnValues = returns.map(value => Promise.reject(value));
break;
}
_this.returns.push(returnMock);
_this._calls.pop();
if (_this.callCount === 0) {
this.returns.push(returnMock);
this._calls.pop();
if (this.callCount === 0) {
// var indexOfSelf = this

@@ -150,6 +133,5 @@ // ._getPropertyState

return context.proxy;
};
return FunctionState;
}());
}
}
exports.FunctionState = FunctionState;
//# sourceMappingURL=FunctionState.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var FunctionState_1 = require("./FunctionState");
var Utilities_1 = require("../Utilities");
var SubstituteBase_1 = require("../SubstituteBase");
var GetPropertyState = /** @class */ (function () {
function GetPropertyState(_property) {
const FunctionState_1 = require("./FunctionState");
const Utilities_1 = require("../Utilities");
const SubstituteBase_1 = require("../SubstituteBase");
class GetPropertyState {
constructor(_property) {
this._property = _property;

@@ -14,31 +14,15 @@ this.returns = Utilities_1.Nothing;

}
Object.defineProperty(GetPropertyState.prototype, "isFunction", {
get: function () {
return !!this._functionState;
},
enumerable: true,
configurable: true
});
Object.defineProperty(GetPropertyState.prototype, "property", {
get: function () {
return this._property;
},
enumerable: true,
configurable: true
});
Object.defineProperty(GetPropertyState.prototype, "callCount", {
get: function () {
return this._callCount;
},
enumerable: true,
configurable: true
});
Object.defineProperty(GetPropertyState.prototype, "functionState", {
get: function () {
return this._functionState;
},
enumerable: true,
configurable: true
});
GetPropertyState.prototype.apply = function (context, args) {
get isFunction() {
return !!this._functionState;
}
get property() {
return this._property;
}
get callCount() {
return this._callCount;
}
get functionState() {
return this._functionState;
}
apply(context, args) {
this._callCount = 0;

@@ -53,7 +37,6 @@ if (this.functionState) {

return context.apply(void 0, void 0, args);
};
GetPropertyState.prototype.set = function (context, property, value) { };
GetPropertyState.prototype.get = function (context, property) {
var _this = this;
var hasExpectations = context.initialState.hasExpectations;
}
set(context, property, value) { }
get(context, property) {
const hasExpectations = context.initialState.hasExpectations;
if (property === 'then')

@@ -64,5 +47,5 @@ return void 0;

if (property === Utilities_1.SubstituteMethods.mimicks) {
return function (input) {
_this.mimicks = input;
_this._callCount--;
return (input) => {
this.mimicks = input;
this._callCount--;
context.state = context.initialState;

@@ -74,9 +57,5 @@ };

throw SubstituteBase_1.SubstituteException.generic('The return value for the property ' + this._property.toString() + ' has already been set to ' + this.returns);
return function () {
var returns = [];
for (var _i = 0; _i < arguments.length; _i++) {
returns[_i] = arguments[_i];
}
_this.returns = returns;
_this._callCount--;
return (...returns) => {
this.returns = returns;
this._callCount--;
context.state = context.initialState;

@@ -86,5 +65,5 @@ };

if (property === Utilities_1.SubstituteMethods.throws) {
return function (callback) {
_this.throws = callback;
_this._callCount--;
return (callback) => {
this.throws = callback;
this._callCount--;
context.state = context.initialState;

@@ -109,6 +88,5 @@ };

return context.proxy;
};
return GetPropertyState;
}());
}
}
exports.GetPropertyState = GetPropertyState;
//# sourceMappingURL=GetPropertyState.js.map
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var SetPropertyState_1 = require("./SetPropertyState");
var Utilities_1 = require("../Utilities");
var Substitute_1 = require("../Substitute");
var SubstituteBase_1 = require("../SubstituteBase");
var InitialState = /** @class */ (function () {
function InitialState() {
const SetPropertyState_1 = require("./SetPropertyState");
const Utilities_1 = require("../Utilities");
const Substitute_1 = require("../Substitute");
const SubstituteBase_1 = require("../SubstituteBase");
class InitialState {
constructor() {
this.recordedGetPropertyStates = new Map();

@@ -34,51 +14,35 @@ this.recordedSetPropertyStates = [];

}
Object.defineProperty(InitialState.prototype, "expectedCount", {
get: function () {
// expected count of calls,
// being assigned with received() method call
return this._expectedCount;
},
enumerable: true,
configurable: true
});
Object.defineProperty(InitialState.prototype, "hasExpectations", {
get: function () {
return this._expectedCount !== void 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(InitialState.prototype, "setPropertyStates", {
get: function () {
return __spread(this.recordedSetPropertyStates);
},
enumerable: true,
configurable: true
});
Object.defineProperty(InitialState.prototype, "getPropertyStates", {
get: function () {
return __spread(this.recordedGetPropertyStates.values());
},
enumerable: true,
configurable: true
});
InitialState.prototype.recordGetPropertyState = function (property, getState) {
get expectedCount() {
// expected count of calls,
// being assigned with received() method call
return this._expectedCount;
}
get hasExpectations() {
return this._expectedCount !== void 0;
}
get setPropertyStates() {
return [...this.recordedSetPropertyStates];
}
get getPropertyStates() {
return [...this.recordedGetPropertyStates.values()];
}
recordGetPropertyState(property, getState) {
this.recordedGetPropertyStates.set(property, getState);
};
InitialState.prototype.recordSetPropertyState = function (setState) {
}
recordSetPropertyState(setState) {
this.recordedSetPropertyStates.push(setState);
};
InitialState.prototype.assertCallCountMatchesExpectations = function (receivedCalls, // list of arguments
}
assertCallCountMatchesExpectations(receivedCalls, // list of arguments
receivedCount, type, // method or property
propertyValue, args) {
var expectedCount = this._expectedCount;
const expectedCount = this._expectedCount;
this.clearExpectations();
if (this.doesCallCountMatchExpectations(expectedCount, receivedCount))
return;
var callCount = { expected: expectedCount, received: receivedCount };
var property = { type: type, value: propertyValue };
var calls = { expectedArguments: args, received: receivedCalls };
const callCount = { expected: expectedCount, received: receivedCount };
const property = { type, value: propertyValue };
const calls = { expectedArguments: args, received: receivedCalls };
throw SubstituteBase_1.SubstituteException.forCallCountMissMatch(callCount, property, calls);
};
InitialState.prototype.doesCallCountMatchExpectations = function (expectedCount, actualCount) {
}
doesCallCountMatchExpectations(expectedCount, actualCount) {
if (expectedCount === void 0)

@@ -89,5 +53,5 @@ return true;

return expectedCount === actualCount;
};
InitialState.prototype.apply = function (context, args) { };
InitialState.prototype.set = function (context, property, value) {
}
apply(context, args) { }
set(context, property, value) {
if (property === Substitute_1.AreProxiesDisabledKey) {

@@ -97,3 +61,3 @@ this._areProxiesDisabled = value;

}
var existingSetState = this.recordedSetPropertyStates.find(function (x) { return x.arguments[0] === value; });
const existingSetState = this.recordedSetPropertyStates.find(x => x.arguments[0] === value);
;

@@ -103,9 +67,8 @@ if (existingSetState) {

}
var setPropertyState = new SetPropertyState_1.SetPropertyState(property, value);
const setPropertyState = new SetPropertyState_1.SetPropertyState(property, value);
setPropertyState.set(context, property, value);
context.state = setPropertyState;
this.recordedSetPropertyStates.push(setPropertyState);
};
InitialState.prototype.get = function (context, property) {
var _this = this;
}
get(context, property) {
switch (property) {

@@ -115,9 +78,9 @@ case Substitute_1.AreProxiesDisabledKey:

case Utilities_1.SubstituteMethods.received:
return function (count) {
_this._expectedCount = count === void 0 ? null : count;
return (count) => {
this._expectedCount = count === void 0 ? null : count;
return context.receivedProxy;
};
case Utilities_1.SubstituteMethods.didNotReceive:
return function () {
_this._expectedCount = 0;
return () => {
this._expectedCount = 0;
return context.receivedProxy;

@@ -128,12 +91,11 @@ };

}
};
InitialState.prototype.clearExpectations = function () {
}
clearExpectations() {
this._expectedCount = void 0;
};
InitialState.prototype.onSwitchedTo = function () {
}
onSwitchedTo() {
this.clearExpectations();
};
return InitialState;
}());
}
}
exports.InitialState = InitialState;
//# sourceMappingURL=InitialState.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Utilities_1 = require("../Utilities");
var SubstituteBase_1 = require("../SubstituteBase");
var SetPropertyState = /** @class */ (function () {
function SetPropertyState(_property) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
const Utilities_1 = require("../Utilities");
const SubstituteBase_1 = require("../SubstituteBase");
class SetPropertyState {
constructor(_property, ...args) {
this._property = _property;

@@ -15,35 +11,23 @@ this._arguments = args;

}
Object.defineProperty(SetPropertyState.prototype, "arguments", {
get: function () {
return this._arguments;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SetPropertyState.prototype, "property", {
get: function () {
return this._property;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SetPropertyState.prototype, "callCount", {
get: function () {
return this._callCount;
},
enumerable: true,
configurable: true
});
SetPropertyState.prototype.apply = function (context) {
get arguments() {
return this._arguments;
}
get property() {
return this._property;
}
get callCount() {
return this._callCount;
}
apply(context) {
throw SubstituteBase_1.SubstituteException.generic('Calling apply of setPropertyState is not normal behaviour, something gone wrong');
};
SetPropertyState.prototype.set = function (context, property, value) {
var callCount = this._callCount;
var hasExpectations = context.initialState.hasExpectations;
}
set(context, property, value) {
let callCount = this._callCount;
const hasExpectations = context.initialState.hasExpectations;
if (hasExpectations) {
callCount = context.initialState
.setPropertyStates
.filter(function (x) { return Utilities_1.areArgumentsEqual(x.arguments[0], value); })
.map(function (x) { return x._callCount; })
.reduce(function (a, b) { return a + b; }, 0);
.filter(x => Utilities_1.areArgumentsEqual(x.arguments[0], value))
.map(x => x._callCount)
.reduce((a, b) => a + b, 0);
}

@@ -55,9 +39,8 @@ context.initialState.assertCallCountMatchesExpectations([[]], // not sure what this was supposed to do

}
};
SetPropertyState.prototype.get = function (context, property) {
}
get(context, property) {
throw SubstituteBase_1.SubstituteException.generic('Calling get of setPropertyState is not normal behaviour, something gone wrong');
};
return SetPropertyState;
}());
}
}
exports.SetPropertyState = SetPropertyState;
//# sourceMappingURL=SetPropertyState.js.map
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Context_1 = require("./Context");
var Utilities_1 = require("./Utilities");
const Context_1 = require("./Context");
const Utilities_1 = require("./Utilities");
exports.HandlerKey = Symbol();
exports.AreProxiesDisabledKey = Symbol();
var Substitute = /** @class */ (function () {
function Substitute() {
class Substitute {
static for() {
const objectContext = new Context_1.Context();
return objectContext.rootProxy;
}
Substitute.for = function () {
var objectContext = new Context_1.Context();
return objectContext.rootProxy;
};
Substitute.disableFor = function (substitute) {
var thisProxy = substitute; // rootProxy
var thisExposedProxy = thisProxy[exports.HandlerKey]; // Context
var disableProxy = function (f) {
static disableFor(substitute) {
const thisProxy = substitute; // rootProxy
const thisExposedProxy = thisProxy[exports.HandlerKey]; // Context
const disableProxy = (f) => {
return function () {
thisProxy[exports.AreProxiesDisabledKey] = true; // for what reason need to do this?
var returnValue = f.call.apply(f, __spread([thisExposedProxy], arguments));
const returnValue = f.call(thisExposedProxy, ...arguments);
thisProxy[exports.AreProxiesDisabledKey] = false;

@@ -45,18 +23,17 @@ return returnValue;

};
return new Proxy(function () { }, {
return new Proxy(() => { }, {
apply: function (_target, _this, args) {
return disableProxy(thisExposedProxy.apply).apply(void 0, __spread(arguments));
return disableProxy(thisExposedProxy.apply)(...arguments);
},
set: function (_target, property, value) {
return disableProxy(thisExposedProxy.set).apply(void 0, __spread(arguments));
return disableProxy(thisExposedProxy.set)(...arguments);
},
get: function (_target, property) {
Utilities_1.Get(thisExposedProxy._initialState, thisExposedProxy, property);
return disableProxy(thisExposedProxy.get).apply(void 0, __spread(arguments));
return disableProxy(thisExposedProxy.get)(...arguments);
}
});
};
return Substitute;
}());
}
}
exports.Substitute = Substitute;
//# sourceMappingURL=Substitute.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("util");
var Utilities_1 = require("./Utilities");
var SubstituteJS = /** @class */ (function () {
function SubstituteJS() {
this.length = "[Function: " + this.constructor.name + "] -> " + this.lastRegisteredSubstituteJSMethodOrProperty;
const util_1 = require("util");
const Utilities_1 = require("./Utilities");
class SubstituteJS {
constructor() {
this.length = `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
}
Object.defineProperty(SubstituteJS.prototype, "lastRegisteredSubstituteJSMethodOrProperty", {
get: function () {
return typeof this._lastRegisteredSubstituteJSMethodOrProperty === 'undefined' ? 'root' : this._lastRegisteredSubstituteJSMethodOrProperty;
},
set: function (value) {
this._lastRegisteredSubstituteJSMethodOrProperty = value;
},
enumerable: true,
configurable: true
});
SubstituteJS.prototype[Symbol.toPrimitive] = function () {
return "[Function: " + this.constructor.name + "] -> " + this.lastRegisteredSubstituteJSMethodOrProperty;
};
SubstituteJS.prototype[Symbol.toStringTag] = function () {
return "[Function: " + this.constructor.name + "] -> " + this.lastRegisteredSubstituteJSMethodOrProperty;
};
SubstituteJS.prototype[Symbol.iterator] = function () {
return "[Function: " + this.constructor.name + "] -> " + this.lastRegisteredSubstituteJSMethodOrProperty;
};
SubstituteJS.prototype[util_1.inspect.custom] = function () {
return "[Function: " + this.constructor.name + "] -> " + this.lastRegisteredSubstituteJSMethodOrProperty;
};
SubstituteJS.prototype.valueOf = function () {
return "[Function: " + this.constructor.name + "] -> " + this.lastRegisteredSubstituteJSMethodOrProperty;
};
SubstituteJS.prototype.$$typeof = function () {
return "[Function: " + this.constructor.name + "] -> " + this.lastRegisteredSubstituteJSMethodOrProperty;
};
SubstituteJS.prototype.toString = function () {
return "[Function: " + this.constructor.name + "] -> " + this.lastRegisteredSubstituteJSMethodOrProperty;
};
SubstituteJS.prototype.inspect = function () {
return "[Function: " + this.constructor.name + "] -> " + this.lastRegisteredSubstituteJSMethodOrProperty;
};
return SubstituteJS;
}());
set lastRegisteredSubstituteJSMethodOrProperty(value) {
this._lastRegisteredSubstituteJSMethodOrProperty = value;
}
get lastRegisteredSubstituteJSMethodOrProperty() {
return typeof this._lastRegisteredSubstituteJSMethodOrProperty === 'undefined' ? 'root' : this._lastRegisteredSubstituteJSMethodOrProperty;
}
[Symbol.toPrimitive]() {
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
}
[Symbol.toStringTag]() {
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
}
[Symbol.iterator]() {
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
}
[util_1.inspect.custom]() {
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
}
valueOf() {
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
}
$$typeof() {
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
}
toString() {
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
}
inspect() {
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
}
}
exports.SubstituteJS = SubstituteJS;

@@ -64,14 +46,11 @@ var SubstituteExceptionTypes;

})(SubstituteExceptionTypes || (SubstituteExceptionTypes = {}));
var SubstituteException = /** @class */ (function (_super) {
__extends(SubstituteException, _super);
function SubstituteException(msg, exceptionType) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
Error.captureStackTrace(_this, SubstituteException);
_this.name = _newTarget.name;
_this.type = exceptionType;
return _this;
class SubstituteException extends Error {
constructor(msg, exceptionType) {
super(msg);
Error.captureStackTrace(this, SubstituteException);
this.name = new.target.name;
this.type = exceptionType;
}
SubstituteException.forCallCountMissMatch = function (callCount, property, calls) {
var message = 'Expected ' + (callCount.expected === null ? '1 or more' : callCount.expected) +
static forCallCountMissMatch(callCount, property, calls) {
const message = 'Expected ' + (callCount.expected === null ? '1 or more' : callCount.expected) +
' call' + (callCount.expected === 1 ? '' : 's') + ' to the ' + property.type + ' ' + property.value.toString() +

@@ -82,12 +61,11 @@ ' with ' + Utilities_1.stringifyArguments(calls.expectedArguments) + ', but received ' + (callCount.received === 0 ? 'none' : callCount.received) +

return new this(message, SubstituteExceptionTypes.CallCountMissMatch);
};
SubstituteException.forPropertyNotMocked = function (property) {
return new this("There is no mock for property: " + String(property), SubstituteExceptionTypes.PropertyNotMocked);
};
SubstituteException.generic = function (message) {
}
static forPropertyNotMocked(property) {
return new this(`There is no mock for property: ${String(property)}`, SubstituteExceptionTypes.PropertyNotMocked);
}
static generic(message) {
return new this(message);
};
return SubstituteException;
}(Error));
}
}
exports.SubstituteException = SubstituteException;
//# sourceMappingURL=SubstituteBase.js.map
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
var Arguments_1 = require("./Arguments");
var GetPropertyState_1 = require("./states/GetPropertyState");
var util = require("util");
const Arguments_1 = require("./Arguments");
const GetPropertyState_1 = require("./states/GetPropertyState");
const util = require("util");
var Type;

@@ -32,5 +21,6 @@ (function (Type) {

})(SubstituteMethods = exports.SubstituteMethods || (exports.SubstituteMethods = {}));
const seenObject = Symbol();
exports.Nothing = Symbol();
function stringifyArguments(args) {
args = args.map(function (x) { return util.inspect(x); });
args = args.map(x => util.inspect(x));
return args && args.length > 0 ? 'arguments [' + args.join(', ') + ']' : 'no arguments';

@@ -41,3 +31,3 @@ }

function areArgumentArraysEqual(a, b) {
if (a.find(function (x) { return x instanceof Arguments_1.AllArguments; }) || b.find(function (b) { return b instanceof Arguments_1.AllArguments; })) {
if (a.find(x => x instanceof Arguments_1.AllArguments) || b.find(b => b instanceof Arguments_1.AllArguments)) {
return true;

@@ -54,19 +44,8 @@ }

function stringifyCalls(calls) {
var e_1, _a;
if (calls.length === 0)
return ' (no calls)';
var output = '';
try {
for (var calls_1 = __values(calls), calls_1_1 = calls_1.next(); !calls_1_1.done; calls_1_1 = calls_1.next()) {
var call = calls_1_1.value;
output += '\n-> call with ' + (call.length ? stringifyArguments(call) : '(no arguments)');
}
let output = '';
for (let call of calls) {
output += '\n-> call with ' + (call.length ? stringifyArguments(call) : '(no arguments)');
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (calls_1_1 && !calls_1_1.done && (_a = calls_1.return)) _a.call(calls_1);
}
finally { if (e_1) throw e_1.error; }
}
return output;

@@ -89,22 +68,13 @@ }

;
function deepEqual(a, b) {
if (Array.isArray(a)) {
if (!Array.isArray(b) || a.length !== b.length)
return false;
for (var i = 0; i < a.length; i++) {
if (!deepEqual(a[i], b[i]))
return false;
}
return true;
}
if (typeof a === 'object' && a !== null && b !== null) {
if (!(typeof b === 'object'))
return false;
function deepEqual(realA, realB, objectReferences = []) {
const a = objectReferences.includes(realA) ? seenObject : realA;
const b = objectReferences.includes(realB) ? seenObject : realB;
const newObjectReferences = updateObjectReferences(objectReferences, a, b);
if (nonNullObject(a) && nonNullObject(b)) {
if (a.constructor !== b.constructor)
return false;
var keys = Object.keys(a);
if (keys.length !== Object.keys(b).length)
if (Object.keys(a).length !== Object.keys(b).length)
return false;
for (var key in a) {
if (!deepEqual(a[key], b[key]))
for (const key in a) {
if (!deepEqual(a[key], b[key], newObjectReferences))
return false;

@@ -116,4 +86,11 @@ }

}
function updateObjectReferences(objectReferences, a, b) {
const tempObjectReferences = [...objectReferences, nonNullObject(a) && !objectReferences.includes(a) ? a : void 0];
return [...tempObjectReferences, nonNullObject(b) && !tempObjectReferences.includes(b) ? b : void 0];
}
function nonNullObject(value) {
return typeof value === 'object' && value !== null;
}
function Get(recorder, context, property) {
var existingGetState = recorder.getPropertyStates.find(function (state) { return state.property === property; });
const existingGetState = recorder.getPropertyStates.find(state => state.property === property);
if (existingGetState) {

@@ -123,3 +100,3 @@ context.state = existingGetState;

}
var getState = new GetPropertyState_1.GetPropertyState(property);
const getState = new GetPropertyState_1.GetPropertyState(property);
context.state = getState;

@@ -126,0 +103,0 @@ recorder.recordGetPropertyState(property, getState);

{
"name": "@fluffy-spoon/substitute",
"version": "1.117.0",
"version": "1.118.0",
"description": "An NSubstitute port to TypeScript called substitute.js.",

@@ -20,3 +20,3 @@ "main": "dist/src/index.js",

"@types/node": "latest",
"ava": "^3.5.0",
"ava": "^3.5.2",
"typescript": "^3.8.3"

@@ -23,0 +23,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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