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.0.62 to 1.0.63

124

dist/spec/index.test.js

@@ -38,5 +38,74 @@ "use strict";

ava_1.default.beforeEach(function () {
console.log('');
console.log('Ava: beforeEach');
console.log('');
instance = new Example();
substitute = Index_1.Substitute.for();
});
ava_1.default('class string field set received', function (t) {
substitute.v = undefined;
substitute.v = null;
substitute.v = 'hello';
substitute.v = 'hello';
substitute.v = 'world';
t.notThrows(function () { return substitute.received().v = 'hello'; });
t.notThrows(function () { return substitute.received(5).v = Index_1.Arg.any(); });
t.notThrows(function () { return substitute.received().v = Index_1.Arg.any(); });
t.notThrows(function () { return substitute.received(2).v = 'hello'; });
t.notThrows(function () { return substitute.received(2).v = Index_1.Arg.is(function (x) { return x && x.indexOf('ll') > -1; }); });
t.throws(function () { return substitute.received(2).v = Index_1.Arg.any(); });
t.throws(function () { return substitute.received(1).v = Index_1.Arg.any(); });
t.throws(function () { return substitute.received(1).v = Index_1.Arg.is(function (x) { return x && x.indexOf('ll') > -1; }); });
t.throws(function () { return substitute.received(3).v = 'hello'; });
});
ava_1.default('class method returns with specific args', function (t) {
substitute.c("hi", "there").returns("blah", "haha");
t.is(substitute.c("hi", "there"), 'blah');
t.is(substitute.c("hi", "the1re"), substitute);
t.deepEqual(substitute.c("hi", "there"), 'haha');
t.is(substitute.c("hi", "there"), void 0);
t.is(substitute.c("hi", "there"), void 0);
});
ava_1.default('partial mocks using function mimicks with specific args', function (t) {
substitute.c('a', 'b').mimicks(instance.c);
t.is(substitute.c('c', 'b'), substitute);
t.is(substitute.c('a', 'b'), 'hello a world (b)');
});
ava_1.default('class method returns with placeholder args', function (t) {
substitute.c(Index_1.Arg.any(), "there").returns("blah", "haha");
t.is(substitute.c("hi", "there"), 'blah');
t.is(substitute.c("hi", "the1re"), substitute);
t.is(substitute.c("his", "there"), 'haha');
t.is(substitute.c("his", "there"), void 0);
t.is(substitute.c("hi", "there"), void 0);
});
ava_1.default('class void returns', function (t) {
substitute.foo().returns(void 0, null);
t.is(substitute.foo(), void 0);
t.is(substitute.foo(), null);
});
ava_1.default('class method received', function (t) {
void substitute.c("hi", "there");
void substitute.c("hi", "the1re");
void substitute.c("hi", "there");
void substitute.c("hi", "there");
void substitute.c("hi", "there");
t.notThrows(function () { return substitute.received(4).c('hi', 'there'); });
t.notThrows(function () { return substitute.received(1).c('hi', 'the1re'); });
t.notThrows(function () { return substitute.received().c('hi', 'there'); });
t.throws(function () { return substitute.received(7).c('hi', 'there'); }, "Expected 7 calls to the method c with arguments [hi, there], but received 4 of such calls.\nAll calls received to method c:\n-> 4 calls with arguments [hi, there]\n-> 1 call with arguments [hi, the1re]");
});
ava_1.default('received call matches after partial mocks using property instance mimicks', function (t) {
substitute.d.mimicks(function () { return instance.d; });
substitute.c('lala', 'bar');
substitute.received(1).c('lala', 'bar');
substitute.received(1).c('lala', 'bar');
t.notThrows(function () { return substitute.received(1).c('lala', 'bar'); });
t.throws(function () { return substitute.received(2).c('lala', 'bar'); }, "Expected 2 calls to the method c with arguments [lala, bar], but received 1 of such call.\nAll calls received to method c:\n-> 1 call with arguments [lala, bar]");
t.deepEqual(substitute.d, 1337);
});
ava_1.default('can call received twice', function (t) {
t.throws(function () { return substitute.received(1337).c('foo', 'bar'); }, "Expected 1337 calls to the method c with arguments [foo, bar], but received none of such calls.\nAll calls received to method c: (no calls)");
t.throws(function () { return substitute.received(2117).c('foo', 'bar'); }, "Expected 2117 calls to the method c with arguments [foo, bar], but received none of such calls.\nAll calls received to method c: (no calls)");
});
ava_1.default('class string field get received', function (t) {

@@ -51,7 +120,2 @@ void substitute.a;

});
ava_1.default('class void returns', function (t) {
substitute.foo().returns(void 0, null);
t.deepEqual(substitute.foo(), void 0);
t.deepEqual(substitute.foo(), null);
});
ava_1.default('class with method called "received" can be used for call count verification when proxies are suspended', function (t) {

@@ -75,15 +139,2 @@ Index_1.Substitute.disableFor(substitute).received(2);

});
ava_1.default('class method received', function (t) {
void substitute.c("hi", "there");
void substitute.c("hi", "the1re");
void substitute.c("hi", "there");
void substitute.c("hi", "there");
void substitute.c("hi", "there");
substitute.received(4).c('hi', 'there');
t.notThrows(function () { return substitute.received(4).c('hi', 'there'); });
t.notThrows(function () { return substitute.received(1).c('hi', 'the1re'); });
t.notThrows(function () { return substitute.received().c('hi', 'there'); });
var err = t.throws(function () { return substitute.received(7).c('hi', 'there'); });
t.deepEqual(err.message, "Expected 7 calls to the method c with arguments [hi, there], but received 4 of such calls.\nAll calls received to method c:\n-> 4 calls with arguments [hi, there]\n-> 1 call with arguments [hi, the1re]");
});
ava_1.default('are arguments equal', function (t) {

@@ -95,23 +146,2 @@ t.true(Utilities_1.areArgumentsEqual(Index_1.Arg.any(), 'hi'));

});
ava_1.default('class method returns with placeholder args', function (t) {
substitute.c(Index_1.Arg.any(), "there").returns("blah", "haha");
t.deepEqual(substitute.c("hi", "there"), 'blah');
t.deepEqual(substitute.c("hi", "the1re"), void 0);
t.deepEqual(substitute.c("his", "there"), 'haha');
t.deepEqual(substitute.c("his", "there"), void 0);
t.deepEqual(substitute.c("hi", "there"), void 0);
});
ava_1.default('partial mocks using function mimicks with specific args', function (t) {
substitute.c('a', 'b').mimicks(instance.c);
t.deepEqual(substitute.c('c', 'b'), void 0);
t.deepEqual(substitute.c('a', 'b'), 'hello a world (b)');
});
ava_1.default('class method returns with specific args', function (t) {
substitute.c("hi", "there").returns("blah", "haha");
t.deepEqual(substitute.c("hi", "there"), 'blah');
t.deepEqual(substitute.c("hi", "the1re"), void 0);
t.deepEqual(substitute.c("hi", "there"), 'haha');
t.deepEqual(substitute.c("hi", "there"), void 0);
t.deepEqual(substitute.c("hi", "there"), void 0);
});
ava_1.default('class string field get returns', function (t) {

@@ -124,18 +154,2 @@ substitute.a.returns("foo", "bar");

});
ava_1.default('class string field set received', function (t) {
substitute.v = undefined;
substitute.v = null;
substitute.v = 'hello';
substitute.v = 'hello';
substitute.v = 'world';
t.throws(function () { return substitute.received(2).v = Index_1.Arg.any(); });
t.throws(function () { return substitute.received(1).v = Index_1.Arg.any(); });
t.throws(function () { return substitute.received(1).v = Index_1.Arg.is(function (x) { return x && x.indexOf('ll') > -1; }); });
t.throws(function () { return substitute.received(3).v = 'hello'; });
t.notThrows(function () { return substitute.received().v = Index_1.Arg.any(); });
t.notThrows(function () { return substitute.received(5).v = Index_1.Arg.any(); });
t.notThrows(function () { return substitute.received().v = 'hello'; });
t.notThrows(function () { return substitute.received(2).v = 'hello'; });
t.notThrows(function () { return substitute.received(2).v = Index_1.Arg.is(function (x) { return x && x.indexOf('ll') > -1; }); });
});
//# sourceMappingURL=index.test.js.map

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

call.negated = negated;
call.propertyName = null;
this.calls.expected = call;

@@ -176,4 +177,6 @@ };

}
else if (thisProperty.type === 'function') {
existingCall.argumentsSnapshot = thisProperty.method.arguments;
}
existingCall.callCount++;
this.fixExistingCallArguments();
return existingCall;

@@ -189,3 +192,3 @@ };

if (existingCallProperty.type === 'function' && existingCall.argumentsSnapshot === null)
existingCall.argumentsSnapshot = existingCallProperty.method.arguments;
this.calls.actual.splice(this.calls.actual.indexOf(existingCall), 1);
}

@@ -192,0 +195,0 @@ }

@@ -62,14 +62,26 @@ "use strict";

var propertyContext = objectContext.property;
if (!propertyContext)
throw new Error('The property context could not be determined while invoking a proxy method.');
if (!propertyContext.name)
throw new Error('The name of the current method could not be found.');
var expected = objectContext.calls.expected;
if (propertyContext.type !== 'function') {
var newMethodPropertyContext = propertyContext.promoteToMethod();
newMethodPropertyContext.method.arguments = argumentsList;
newMethodPropertyContext.method.returnValues = null;
}
var existingCalls = objectContext.findActualMethodCalls(propertyContext.name, argumentsList);
var existingCall = existingCalls[0];
var allCalls = objectContext.findActualMethodCalls(propertyContext.name);
if (propertyContext.type === 'function') {
var expected = objectContext.calls.expected;
if (expected && expected.callCount !== void 0) {
expected.arguments = argumentsList;
expected.propertyName = propertyContext.name;
thisProxy[areProxiesDisabledKey] = false;
_this.assertCallMatchCount('method', expected, allCalls, existingCalls);
return void 0;
}
if (propertyContext.type === 'object')
throw new Error('An error occured while promoting a property to a method.');
var hasExpected = expected && expected.callCount !== void 0;
if (hasExpected) {
expected.arguments = argumentsList;
expected.propertyName = propertyContext.name;
objectContext.fixExistingCallArguments();
_this.assertCallMatchCount('method', thisProxy, objectContext, allCalls, existingCalls);
return void 0;
}
else {
if (existingCall) {

@@ -82,16 +94,13 @@ existingCall.callCount++;

}
if (propertyContext.method.returnValues)
return propertyContext.method.returnValues[existingCall.callCount - 1];
}
else {
propertyContext.method.arguments = argumentsList;
objectContext.addActualPropertyCall();
return void 0;
if (!expected)
objectContext.addActualPropertyCall();
if (isProxyDisabled())
return void 0;
}
if (propertyContext.method.returnValues)
return propertyContext.method.returnValues[existingCall.callCount - 1];
return void 0;
}
var newMethodPropertyContext = propertyContext.promoteToMethod();
newMethodPropertyContext.method.arguments = argumentsList;
newMethodPropertyContext.method.returnValues = null;
objectContext.fixExistingCallArguments();
return thisProxy;

@@ -104,17 +113,19 @@ },

}
var expected = objectContext.calls.expected;
var argumentsList = [value];
var existingCalls = objectContext.findActualMethodCalls(property.toString(), argumentsList);
if (expected && expected.callCount !== void 0) {
expected.arguments = argumentsList;
expected.propertyName = property.toString();
_this.assertCallMatchCount('property', thisProxy, objectContext, objectContext.findActualMethodCalls(property.toString()), existingCalls);
return true;
}
var propertyContext = objectContext.property;
var argumentsList = [value];
var existingCalls = objectContext.findActualMethodCalls(propertyContext.name, argumentsList);
if (existingCalls.length > 0 && propertyContext.type === 'function') {
var expected = objectContext.calls.expected;
if (expected && expected.callCount !== void 0) {
expected.arguments = argumentsList;
expected.propertyName = propertyContext.name;
thisProxy[areProxiesDisabledKey] = false;
_this.assertCallMatchCount('property', expected, objectContext.findActualMethodCalls(propertyContext.name), existingCalls);
if (propertyContext) {
if (existingCalls.length > 0 && propertyContext.type === 'function') {
var existingCall = existingCalls[0];
if (!expected)
existingCall.callCount++;
return true;
}
var existingCall = existingCalls[0];
existingCall.callCount++;
return true;
}

@@ -127,3 +138,4 @@ var newMethodPropertyContext = new Context_1.ProxyMethodPropertyContext();

objectContext.property = newMethodPropertyContext;
objectContext.addActualPropertyCall();
if (!expected)
objectContext.addActualPropertyCall();
return true;

@@ -137,2 +149,4 @@ },

return function () { return void 0; };
if (property === Symbol.toStringTag)
return void 0;
}

@@ -149,12 +163,13 @@ if (property === 'valueOf')

var addPropertyToObjectContext = function () {
var expected = objectContext.calls.expected;
var existingCall = objectContext.findActualPropertyCalls(property.toString())[0] || null;
if (existingCall) {
var existingCallProperty = existingCall.property;
if (existingCallProperty.type === 'function')
if (existingCallProperty.type === 'function') {
objectContext.property = existingCallProperty;
return thisProxy;
var expected = objectContext.calls.expected;
}
if (expected && expected.callCount !== void 0) {
expected.propertyName = existingCallProperty.name;
thisProxy[areProxiesDisabledKey] = false;
_this.assertCallMatchCount('property', expected, [existingCall], [existingCall]);
_this.assertCallMatchCount('property', thisProxy, objectContext, [existingCall], [existingCall]);
return thisProxy;

@@ -175,3 +190,4 @@ }

objectContext.property = newPropertyContext;
objectContext.addActualPropertyCall();
if (!expected)
objectContext.addActualPropertyCall();
return thisProxy;

@@ -199,2 +215,4 @@ };

return function (value) {
objectContext.property = null;
objectContext.calls.expected = null;
context.returnValues = void 0;

@@ -237,3 +255,7 @@ context.mimicks = value;

};
Substitute.assertCallMatchCount = function (type, expected, allCalls, matchingCalls) {
Substitute.assertCallMatchCount = function (type, thisProxy, objectContext, allCalls, matchingCalls) {
var expected = objectContext.calls.expected;
objectContext.property = null;
objectContext.calls.expected = null;
thisProxy[areProxiesDisabledKey] = false;
var getCallCounts = function (calls) {

@@ -240,0 +262,0 @@ var callCounts = calls.map(function (x) { return x.callCount; });

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

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

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

@@ -30,3 +30,6 @@ "typescript": "^3.0.0"

],
"cache": false,
"concurrency": 1,
"failFast": true,
"failWithoutAssertions": true,
"compileEnhancements": false,

@@ -33,0 +36,0 @@ "extensions": [

@@ -35,2 +35,6 @@ import test from 'ava';

test.beforeEach(() => {
console.log('');
console.log('Ava: beforeEach')
console.log('');
instance = new Example();

@@ -40,2 +44,99 @@ substitute = Substitute.for<Example>();

test('class string field set received', t => {
substitute.v = undefined;
substitute.v = null;
substitute.v = 'hello';
substitute.v = 'hello';
substitute.v = 'world';
t.notThrows(() => substitute.received().v = 'hello');
t.notThrows(() => substitute.received(5).v = Arg.any());
t.notThrows(() => substitute.received().v = Arg.any());
t.notThrows(() => substitute.received(2).v = 'hello');
t.notThrows(() => substitute.received(2).v = Arg.is(x => x && x.indexOf('ll') > -1));
t.throws(() => substitute.received(2).v = Arg.any());
t.throws(() => substitute.received(1).v = Arg.any());
t.throws(() => substitute.received(1).v = Arg.is(x => x && x.indexOf('ll') > -1));
t.throws(() => substitute.received(3).v = 'hello');
});
test('class method returns with specific args', t => {
substitute.c("hi", "there").returns("blah", "haha");
t.is(substitute.c("hi", "there"), 'blah');
t.is<any>(substitute.c("hi", "the1re"), substitute);
t.deepEqual(substitute.c("hi", "there"), 'haha');
t.is(substitute.c("hi", "there"), void 0);
t.is(substitute.c("hi", "there"), void 0);
});
test('partial mocks using function mimicks with specific args', t => {
substitute.c('a', 'b').mimicks(instance.c);
t.is<any>(substitute.c('c', 'b'), substitute);
t.is(substitute.c('a', 'b'), 'hello a world (b)');
});
test('class method returns with placeholder args', t => {
substitute.c(Arg.any(), "there").returns("blah", "haha");
t.is(substitute.c("hi", "there"), 'blah');
t.is<any>(substitute.c("hi", "the1re"), substitute);
t.is(substitute.c("his", "there"), 'haha');
t.is<any>(substitute.c("his", "there"), void 0);
t.is<any>(substitute.c("hi", "there"), void 0);
});
test('class void returns', t => {
substitute.foo().returns(void 0, null);
t.is(substitute.foo(), void 0);
t.is(substitute.foo(), null);
});
test('class method received', t => {
void substitute.c("hi", "there");
void substitute.c("hi", "the1re");
void substitute.c("hi", "there");
void substitute.c("hi", "there");
void substitute.c("hi", "there");
t.notThrows(() => substitute.received(4).c('hi', 'there'));
t.notThrows(() => substitute.received(1).c('hi', 'the1re'));
t.notThrows(() => substitute.received().c('hi', 'there'));
t.throws(() => substitute.received(7).c('hi', 'there'),
`Expected 7 calls to the method c with arguments [hi, there], but received 4 of such calls.
All calls received to method c:
-> 4 calls with arguments [hi, there]
-> 1 call with arguments [hi, the1re]`);
});
test('received call matches after partial mocks using property instance mimicks', t => {
substitute.d.mimicks(() => instance.d);
substitute.c('lala', 'bar');
substitute.received(1).c('lala', 'bar');
substitute.received(1).c('lala', 'bar');
t.notThrows(() => substitute.received(1).c('lala', 'bar'));
t.throws(() => substitute.received(2).c('lala', 'bar'),
`Expected 2 calls to the method c with arguments [lala, bar], but received 1 of such call.
All calls received to method c:
-> 1 call with arguments [lala, bar]`);
t.deepEqual(substitute.d, 1337);
});
test('can call received twice', t => {
t.throws(() => substitute.received(1337).c('foo', 'bar'),
`Expected 1337 calls to the method c with arguments [foo, bar], but received none of such calls.
All calls received to method c: (no calls)`);
t.throws(() => substitute.received(2117).c('foo', 'bar'),
`Expected 2117 calls to the method c with arguments [foo, bar], but received none of such calls.
All calls received to method c: (no calls)`);
});
test('class string field get received', t => {

@@ -52,9 +153,2 @@ void substitute.a;

test('class void returns', t => {
substitute.foo().returns(void 0, null);
t.deepEqual(substitute.foo(), void 0);
t.deepEqual(substitute.foo(), null);
});
test('class with method called "received" can be used for call count verification when proxies are suspended', t => {

@@ -86,23 +180,2 @@ Substitute.disableFor(substitute).received(2);

test('class method received', t => {
void substitute.c("hi", "there");
void substitute.c("hi", "the1re");
void substitute.c("hi", "there");
void substitute.c("hi", "there");
void substitute.c("hi", "there");
substitute.received(4).c('hi', 'there')
t.notThrows(() => substitute.received(4).c('hi', 'there'));
t.notThrows(() => substitute.received(1).c('hi', 'the1re'));
t.notThrows(() => substitute.received().c('hi', 'there'));
const err: Error = t.throws(() => substitute.received(7).c('hi', 'there'));
t.deepEqual(err.message,
`Expected 7 calls to the method c with arguments [hi, there], but received 4 of such calls.
All calls received to method c:
-> 4 calls with arguments [hi, there]
-> 1 call with arguments [hi, the1re]`);
});
test('are arguments equal', t => {

@@ -116,29 +189,2 @@ t.true(areArgumentsEqual(Arg.any(), 'hi'));

test('class method returns with placeholder args', t => {
substitute.c(Arg.any(), "there").returns("blah", "haha");
t.deepEqual(substitute.c("hi", "there"), 'blah');
t.deepEqual(substitute.c("hi", "the1re"), void 0);
t.deepEqual(substitute.c("his", "there"), 'haha');
t.deepEqual(substitute.c("his", "there"), void 0);
t.deepEqual(substitute.c("hi", "there"), void 0);
});
test('partial mocks using function mimicks with specific args', t => {
substitute.c('a', 'b').mimicks(instance.c);
t.deepEqual(substitute.c('c', 'b'), void 0);
t.deepEqual(substitute.c('a', 'b'), 'hello a world (b)');
});
test('class method returns with specific args', t => {
substitute.c("hi", "there").returns("blah", "haha");
t.deepEqual(substitute.c("hi", "there"), 'blah');
t.deepEqual(substitute.c("hi", "the1re"), void 0);
t.deepEqual(substitute.c("hi", "there"), 'haha');
t.deepEqual(substitute.c("hi", "there"), void 0);
t.deepEqual(substitute.c("hi", "there"), void 0);
});
test('class string field get returns', t => {

@@ -151,20 +197,2 @@ substitute.a.returns("foo", "bar");

t.deepEqual(substitute.a, void 0);
});
test('class string field set received', t => {
substitute.v = undefined;
substitute.v = null;
substitute.v = 'hello';
substitute.v = 'hello';
substitute.v = 'world';
t.throws(() => substitute.received(2).v = Arg.any());
t.throws(() => substitute.received(1).v = Arg.any());
t.throws(() => substitute.received(1).v = Arg.is(x => x && x.indexOf('ll') > -1));
t.throws(() => substitute.received(3).v = 'hello');
t.notThrows(() => substitute.received().v = Arg.any());
t.notThrows(() => substitute.received(5).v = Arg.any());
t.notThrows(() => substitute.received().v = 'hello');
t.notThrows(() => substitute.received(2).v = 'hello');
t.notThrows(() => substitute.received(2).v = Arg.is(x => x && x.indexOf('ll') > -1));
});

@@ -91,2 +91,3 @@ import { areArgumentsEqual } from "./Utilities";

call.negated = negated;
call.propertyName = null;

@@ -166,2 +167,4 @@ this.calls.expected = call;

this.calls.actual.push(existingCall);
} else if(thisProperty.type === 'function') {
existingCall.argumentsSnapshot = thisProperty.method.arguments;
}

@@ -171,4 +174,2 @@

this.fixExistingCallArguments();
return existingCall;

@@ -182,3 +183,3 @@ }

if(existingCallProperty.type === 'function' && existingCall.argumentsSnapshot === null)
existingCall.argumentsSnapshot = existingCallProperty.method.arguments;
this.calls.actual.splice(this.calls.actual.indexOf(existingCall), 1);
}

@@ -185,0 +186,0 @@ }

@@ -49,3 +49,15 @@ import { ObjectSubstitute, OmitProxyMethods, DisabledSubstituteObject } from "./Transformations";

const propertyContext = objectContext.property;
if(!propertyContext)
throw new Error('The property context could not be determined while invoking a proxy method.');
if(!propertyContext.name)
throw new Error('The name of the current method could not be found.');
const expected = objectContext.calls.expected;
if(propertyContext.type !== 'function') {
const newMethodPropertyContext = propertyContext.promoteToMethod();
newMethodPropertyContext.method.arguments = argumentsList;
newMethodPropertyContext.method.returnValues = null;
}
const existingCalls = objectContext.findActualMethodCalls(propertyContext.name, argumentsList);

@@ -55,17 +67,19 @@ const existingCall = existingCalls[0];

const allCalls = objectContext.findActualMethodCalls(propertyContext.name);
if(propertyContext.type === 'object')
throw new Error('An error occured while promoting a property to a method.');
if (propertyContext.type === 'function') {
const expected = objectContext.calls.expected;
if(expected && expected.callCount !== void 0) {
expected.arguments = argumentsList;
expected.propertyName = propertyContext.name;
thisProxy[areProxiesDisabledKey] = false;
this.assertCallMatchCount('method', expected,
allCalls,
existingCalls);
return void 0;
}
const hasExpected = expected && expected.callCount !== void 0;
if(hasExpected) {
expected.arguments = argumentsList;
expected.propertyName = propertyContext.name;
objectContext.fixExistingCallArguments();
this.assertCallMatchCount('method', thisProxy, objectContext,
allCalls,
existingCalls);
return void 0;
} else {
if(existingCall) {

@@ -79,21 +93,16 @@ existingCall.callCount++;

}
if(propertyContext.method.returnValues)
return propertyContext.method.returnValues[existingCall.callCount - 1];
} else {
propertyContext.method.arguments = argumentsList;
objectContext.addActualPropertyCall();
return void 0;
if(!expected)
objectContext.addActualPropertyCall();
if(isProxyDisabled())
return void 0;
}
if(propertyContext.method.returnValues)
return propertyContext.method.returnValues[existingCall.callCount - 1];
return void 0;
}
const newMethodPropertyContext = propertyContext.promoteToMethod();
newMethodPropertyContext.method.arguments = argumentsList;
newMethodPropertyContext.method.returnValues = null;
objectContext.fixExistingCallArguments();
return thisProxy;

@@ -107,24 +116,27 @@ },

const propertyContext = objectContext.property;
const expected = objectContext.calls.expected;
const argumentsList = [value];
let existingCalls = objectContext.findActualMethodCalls(property.toString(), argumentsList);
if (expected && expected.callCount !== void 0) {
expected.arguments = argumentsList;
expected.propertyName = property.toString();
let existingCalls = objectContext.findActualMethodCalls(propertyContext.name, argumentsList);
if (existingCalls.length > 0 && propertyContext.type === 'function') {
const expected = objectContext.calls.expected;
if (expected && expected.callCount !== void 0) {
expected.arguments = argumentsList;
expected.propertyName = propertyContext.name;
thisProxy[areProxiesDisabledKey] = false;
this.assertCallMatchCount('property', thisProxy, objectContext,
objectContext.findActualMethodCalls(property.toString()),
existingCalls);
this.assertCallMatchCount('property', expected,
objectContext.findActualMethodCalls(propertyContext.name),
existingCalls);
return true;
}
const propertyContext = objectContext.property;
if(propertyContext) {
if (existingCalls.length > 0 && propertyContext.type === 'function') {
const existingCall = existingCalls[0];
if(!expected)
existingCall.callCount++;
return true;
}
const existingCall = existingCalls[0];
existingCall.callCount++;
return true;
}

@@ -140,3 +152,4 @@

objectContext.addActualPropertyCall();
if(!expected)
objectContext.addActualPropertyCall();

@@ -152,2 +165,5 @@ return true;

return () => void 0;
if(property === Symbol.toStringTag)
return void 0;
}

@@ -169,18 +185,18 @@

const addPropertyToObjectContext = () => {
const expected = objectContext.calls.expected;
const existingCall = objectContext.findActualPropertyCalls(property.toString())[0] || null;
if (existingCall) {
const existingCallProperty = existingCall.property;
if (existingCallProperty.type === 'function')
if (existingCallProperty.type === 'function') {
objectContext.property = existingCallProperty;
return thisProxy;
}
const expected = objectContext.calls.expected;
if (expected && expected.callCount !== void 0) {
expected.propertyName = existingCallProperty.name;
thisProxy[areProxiesDisabledKey] = false;
this.assertCallMatchCount('property', expected, [existingCall], [existingCall]);
this.assertCallMatchCount('property', thisProxy, objectContext, [existingCall], [existingCall]);
return thisProxy;
}
existingCall.callCount++;

@@ -205,3 +221,4 @@

objectContext.addActualPropertyCall();
if(!expected)
objectContext.addActualPropertyCall();

@@ -231,2 +248,5 @@ return thisProxy;

return (value: Function) => {
objectContext.property = null;
objectContext.calls.expected = null;
context.returnValues = void 0;

@@ -279,6 +299,13 @@ context.mimicks = value;

type: 'property' | 'method',
expected: ProxyExpectation,
thisProxy: any,
objectContext: ProxyObjectContext,
allCalls: ProxyCallRecord[],
matchingCalls: ProxyCallRecord[]): void
{
const expected = objectContext.calls.expected;
objectContext.property = null;
objectContext.calls.expected = null;
thisProxy[areProxiesDisabledKey] = false;
const getCallCounts = (calls: ProxyCallRecord[]) => {

@@ -285,0 +312,0 @@ const callCounts = calls.map(x => x.callCount);

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