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.69.0 to 1.70.0

dist/spec/issues/18.test.d.ts

1

dist/spec/issues/15.test.js

@@ -5,3 +5,2 @@ "use strict";

var Index_1 = require("../../src/Index");
var substitute = Index_1.Substitute.for();
ava_1.default('issue 15: can call properties twice', function (t) {

@@ -8,0 +7,0 @@ var baz = "baz";

export declare class Argument<T> {
private description;
private matchingFunction;
encounteredValues: any[];
constructor(description: string, matchingFunction: (arg: T) => boolean);

@@ -5,0 +6,0 @@ matches(arg: T): boolean;

@@ -20,2 +20,3 @@ "use strict";

this.matchingFunction = matchingFunction;
this.encounteredValues = [];
}

@@ -37,3 +38,3 @@ Argument.prototype.matches = function (arg) {

function AllArguments() {
return _super.call(this, '{all arguments}', function () { return true; }) || this;
return _super.call(this, '{all}', function () { return true; }) || this;
}

@@ -50,3 +51,3 @@ return AllArguments;

Arg.any = function (type) {
var description = !type ? '{any arg}' : '{arg matching ' + type + '}';
var description = !type ? '{any arg}' : '{type ' + type + '}';
return new Argument(description, function (x) {

@@ -63,3 +64,3 @@ if (!type)

Arg.is = function (predicate) {
return new Argument('{arg matching predicate ' + this.toStringify(predicate) + '}', predicate);
return new Argument('{predicate ' + this.toStringify(predicate) + '}', predicate);
};

@@ -66,0 +67,0 @@ Arg.toStringify = function (obj) {

@@ -36,7 +36,5 @@ "use strict";

Context.prototype.apply = function (args) {
// console.log('apply', args);
return this._state.apply(this, args);
};
Context.prototype.set = function (property, value) {
// console.log('set', property, value);
return this._state.set(this, property, value);

@@ -47,10 +45,2 @@ };

return this;
// const uninterestingProperties = [
// '$$typeof',
// 'constructor',
// 'name',
// 'call'
// ];
// if(typeof property !== 'symbol' && uninterestingProperties.indexOf(property.toString()) === -1)
// console.log('get', property);
return this._state.get(this, property);

@@ -86,3 +76,2 @@ };

state.onSwitchedTo(this);
// console.log('state', state);
},

@@ -89,0 +78,0 @@ enumerable: true,

"use strict";
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
Object.defineProperty(exports, "__esModule", { value: true });
var Utilities_1 = require("../Utilities");
var Arguments_1 = require("../Arguments");
var Nothing = Symbol();

@@ -38,8 +49,10 @@ var FunctionState = /** @class */ (function () {

FunctionState.prototype.apply = function (context, args) {
var e_1, _a, e_2, _b;
var callCount = this._callCount;
var hasExpectations = context.initialState.hasExpectations;
var matchingFunctionStates = this._getPropertyState
.recordedFunctionStates
.filter(function (x) { return Utilities_1.areArgumentArraysEqual(x.arguments, args); });
if (hasExpectations) {
callCount = this._getPropertyState
.recordedFunctionStates
.filter(function (x) { return Utilities_1.areArgumentArraysEqual(x.arguments, args); })
callCount = matchingFunctionStates
.map(function (x) { return x.callCount; })

@@ -49,4 +62,38 @@ .reduce(function (a, b) { return a + b; }, 0);

context.initialState.assertCallCountMatchesExpectations(this._getPropertyState.recordedFunctionStates, callCount, 'method', this.property, args);
if (!hasExpectations)
if (!hasExpectations) {
this._callCount++;
try {
for (var matchingFunctionStates_1 = __values(matchingFunctionStates), matchingFunctionStates_1_1 = matchingFunctionStates_1.next(); !matchingFunctionStates_1_1.done; matchingFunctionStates_1_1 = matchingFunctionStates_1.next()) {
var matchingFunctionState = matchingFunctionStates_1_1.value;
try {
for (var _c = __values(matchingFunctionState.arguments), _d = _c.next(); !_d.done; _d = _c.next()) {
var argument = _d.value;
if (!(argument instanceof Arguments_1.Argument))
continue;
var indexOffset = matchingFunctionState
.arguments
.indexOf(argument);
var myArg = args[indexOffset];
if (myArg instanceof Arguments_1.Argument)
continue;
argument.encounteredValues.push(myArg);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (matchingFunctionStates_1_1 && !matchingFunctionStates_1_1.done && (_a = matchingFunctionStates_1.return)) _a.call(matchingFunctionStates_1);
}
finally { if (e_1) throw e_1.error; }
}
}
if (this.mimicks)

@@ -69,3 +116,2 @@ return this.mimicks.apply(this.mimicks, args);

return function (input) {
// console.log('mimicks', input);
_this.mimicks = input;

@@ -80,3 +126,2 @@ _this._callCount--;

return function () {
// console.log('returns', returns);
var returns = [];

@@ -83,0 +128,0 @@ for (var _i = 0; _i < arguments.length; _i++) {

@@ -65,3 +65,2 @@ "use strict";

if (matchingFunctionState) {
// console.log('ex-func');
return matchingFunctionState.apply(context, args);

@@ -72,3 +71,2 @@ }

this._recordedFunctionStates.push(functionState);
// console.log('states', this._recordedFunctionStates);
return context.apply(args);

@@ -87,3 +85,2 @@ };

return function (input) {
// console.log('mimicks', input);
_this.mimicks = input;

@@ -98,3 +95,2 @@ _this._callCount--;

return function () {
// console.log('returns', returns);
var returns = [];

@@ -101,0 +97,0 @@ for (var _i = 0; _i < arguments.length; _i++) {

@@ -63,3 +63,2 @@ "use strict";

var expectedCount = this._expectedCount;
// console.log('exp-match', expectedCount, callCount);
this.clearExpectations();

@@ -87,3 +86,2 @@ if (this.doesCallCountMatchExpectations(expectedCount, callCount))

if (existingSetState) {
// console.log('ex-prop');
return existingSetState.set(context, property, value);

@@ -94,3 +92,2 @@ }

this.recordedSetPropertyStates.push(setPropertyState);
// console.log('states', this.recordedSetPropertyStates);
setPropertyState.set(context, property, value);

@@ -126,3 +123,2 @@ };

return function (count) {
// console.log('expectation', count);
_this._expectedCount = count === void 0 ? null : count;

@@ -143,3 +139,2 @@ return context.proxy;

InitialState.prototype.clearExpectations = function () {
// console.log('reset-exp');
this._expectedCount = void 0;

@@ -146,0 +141,0 @@ };

@@ -49,6 +49,6 @@ "use strict";

}
// console.log('prop', property, value, callCount);
context.initialState.assertCallCountMatchesExpectations(context.initialState.setPropertyStates, callCount, 'property', this.property, this.arguments);
if (!hasExpectations)
if (!hasExpectations) {
this._callCount++;
}
};

@@ -55,0 +55,0 @@ SetPropertyState.prototype.get = function (context, property) {

@@ -56,6 +56,36 @@ "use strict";

function areArgumentsEqual(a, b) {
var e_2, _a, e_3, _b;
if (a instanceof Arguments_1.AllArguments || b instanceof Arguments_1.AllArguments)
return true;
if (a instanceof Arguments_1.Argument && b instanceof Arguments_1.Argument)
return a.matches(b) && b.matches(a);
if (a instanceof Arguments_1.Argument && b instanceof Arguments_1.Argument) {
try {
for (var _c = __values(a.encounteredValues), _d = _c.next(); !_d.done; _d = _c.next()) {
var encounteredValue = _d.value;
if (!b.matches(encounteredValue))
return false;
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
try {
for (var _e = __values(b.encounteredValues), _f = _e.next(); !_f.done; _f = _e.next()) {
var encounteredValue = _f.value;
if (!a.matches(encounteredValue))
return false;
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_3) throw e_3.error; }
}
return true;
}
if (a instanceof Arguments_1.Argument)

@@ -62,0 +92,0 @@ return a.matches(b);

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

@@ -15,3 +15,3 @@ "main": "dist/src/Index.js",

"@types/node": "latest",
"ava": "^1.2.0",
"ava": "^1.2.1",
"ts-node": "^7.0.1",

@@ -18,0 +18,0 @@ "typescript": "^3.3.1"

import test from 'ava';
import { Substitute } from '../../src/Index';
import { ObjectSubstitute } from '../../src/Transformations';

@@ -10,4 +9,2 @@ export interface Example {

let substitute = Substitute.for<Example>();
test('issue 15: can call properties twice', t => {

@@ -14,0 +11,0 @@ const baz = "baz";

export class Argument<T> {
encounteredValues: any[];
constructor(

@@ -6,2 +8,3 @@ private description: string,

) {
this.encounteredValues = [];
}

@@ -24,3 +27,3 @@

constructor() {
super('{all arguments}', () => true);
super('{all}', () => true);
}

@@ -42,3 +45,3 @@ }

static any(type?: string): Argument<any> & any {
const description = !type ? '{any arg}' : '{arg matching ' + type + '}';
const description = !type ? '{any arg}' : '{type ' + type + '}';
return new Argument<any>(description, x => {

@@ -59,3 +62,3 @@ if(!type)

static is<T>(predicate: (input: T) => boolean): Argument<T> & T {
return new Argument<T>('{arg matching predicate ' + this.toStringify(predicate) + '}', predicate) as any;
return new Argument<T>('{predicate ' + this.toStringify(predicate) + '}', predicate) as any;
}

@@ -62,0 +65,0 @@

@@ -45,3 +45,2 @@ import { ContextState } from "./states/ContextState";

apply(args: any[]) {
// console.log('apply', args);
return this._state.apply(this, args);

@@ -51,3 +50,2 @@ }

set(property: PropertyKey, value: any) {
// console.log('set', property, value);
return this._state.set(this, property, value);

@@ -60,11 +58,2 @@ }

// const uninterestingProperties = [
// '$$typeof',
// 'constructor',
// 'name',
// 'call'
// ];
// if(typeof property !== 'symbol' && uninterestingProperties.indexOf(property.toString()) === -1)
// console.log('get', property);
return this._state.get(this, property);

@@ -92,5 +81,3 @@ }

state.onSwitchedTo(this);
// console.log('state', state);
}
}

@@ -5,2 +5,3 @@ import { ContextState, PropertyKey } from "./ContextState";

import { GetPropertyState } from "./GetPropertyState";
import { Argument } from "../Arguments";

@@ -37,6 +38,7 @@ const Nothing = Symbol();

const hasExpectations = context.initialState.hasExpectations;
const matchingFunctionStates = this._getPropertyState
.recordedFunctionStates
.filter(x => areArgumentArraysEqual(x.arguments, args));
if(hasExpectations) {
callCount = this._getPropertyState
.recordedFunctionStates
.filter(x => areArgumentArraysEqual(x.arguments, args))
callCount = matchingFunctionStates
.map(x => x.callCount)

@@ -53,5 +55,21 @@ .reduce((a, b) => a + b, 0);

if(!hasExpectations)
if(!hasExpectations) {
this._callCount++;
for(let matchingFunctionState of matchingFunctionStates)
for(let argument of matchingFunctionState.arguments) {
if(!(argument instanceof Argument))
continue;
const indexOffset = matchingFunctionState
.arguments
.indexOf(argument);
const myArg = args[indexOffset];
if(myArg instanceof Argument)
continue;
argument.encounteredValues.push(myArg);
}
}
if(this.mimicks)

@@ -79,4 +97,2 @@ return this.mimicks.apply(this.mimicks, args);

return (input: Function) => {
// console.log('mimicks', input);
this.mimicks = input;

@@ -94,4 +110,2 @@ this._callCount--;

return (...returns: any[]) => {
// console.log('returns', returns);
this.returns = returns;

@@ -98,0 +112,0 @@ this._callCount--;

@@ -42,3 +42,2 @@ import { ContextState, PropertyKey } from "./ContextState";

if(matchingFunctionState) {
// console.log('ex-func');
return matchingFunctionState.apply(context, args);

@@ -52,4 +51,2 @@ }

// console.log('states', this._recordedFunctionStates);
return context.apply(args);

@@ -72,4 +69,2 @@ }

return (input: Function) => {
// console.log('mimicks', input);
this.mimicks = input;

@@ -87,4 +82,2 @@ this._callCount--;

return (...returns: any[]) => {
// console.log('returns', returns);
this.returns = returns;

@@ -91,0 +84,0 @@ this._callCount--;

@@ -40,3 +40,2 @@ import { ContextState, PropertyKey } from "./ContextState";

const expectedCount = this._expectedCount;
// console.log('exp-match', expectedCount, callCount);

@@ -72,3 +71,2 @@ this.clearExpectations();

if (existingSetState) {
// console.log('ex-prop');
return existingSetState.set(context, property, value);

@@ -82,4 +80,2 @@ }

// console.log('states', this.recordedSetPropertyStates);
setPropertyState.set(context, property, value);

@@ -126,4 +122,2 @@ }

return (count?: number) => {
// console.log('expectation', count);
this._expectedCount = count === void 0 ? null : count;

@@ -149,3 +143,2 @@ return context.proxy;

private clearExpectations() {
// console.log('reset-exp');
this._expectedCount = void 0;

@@ -152,0 +145,0 @@ }

@@ -44,4 +44,2 @@ import { ContextState, PropertyKey } from "./ContextState";

// console.log('prop', property, value, callCount);
context.initialState.assertCallCountMatchesExpectations(

@@ -54,4 +52,5 @@ context.initialState.setPropertyStates,

if(!hasExpectations)
if(!hasExpectations) {
this._callCount++;
}
}

@@ -58,0 +57,0 @@

@@ -42,5 +42,16 @@ import { Argument, AllArguments } from "./Arguments";

if(a instanceof Argument && b instanceof Argument)
return a.matches(b) && b.matches(a);
if(a instanceof Argument && b instanceof Argument) {
for(let encounteredValue of a.encounteredValues) {
if(!b.matches(encounteredValue))
return false;
}
for(let encounteredValue of b.encounteredValues) {
if(!a.matches(encounteredValue))
return false;
}
return true;
}
if(a instanceof Argument)

@@ -47,0 +58,0 @@ return a.matches(b);

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