Skip to content

Commit

Permalink
add callId = 0 in sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
remorses committed Jan 4, 2024
1 parent d2b43cf commit fabf95c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/sinon/proxy-invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const bind = Function.prototype.bind;

module.exports = function invoke(func, thisValue, args, ctx = globalContext) {
const matchings = this.matchingFakes(args);
if (ctx.callId == null) {

Check failure on line 15 in lib/sinon/proxy-invoke.js

View workflow job for this annotation

GitHub Actions / lint

Use '===' to compare with null
ctx.callId = 0;

Check warning on line 16 in lib/sinon/proxy-invoke.js

View check run for this annotation

Codecov / codecov/patch

lib/sinon/proxy-invoke.js#L16

Added line #L16 was not covered by tests
}
const currentCallId = ctx.callId++;
let exception, returnValue;

Expand Down
2 changes: 1 addition & 1 deletion lib/sinon/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function createProxy(func, originalFunc, ctx = globalContext) {
return proxy;
}

function wrapFunction(func, originalFunc, ctx) {
function wrapFunction(func, originalFunc, ctx = globalContext) {
const arity = originalFunc.length;
let p;
// Do not change this to use an eval. Projects that depend on sinon block the use of eval.
Expand Down
1 change: 1 addition & 0 deletions lib/sinon/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function checkForValidArguments(descriptor, property, replacement) {
*/
function Sandbox(opts = {}) {
const sandbox = this;
sandbox.callId = 0;
const assertOptions = opts.assertOptions || {};
let fakeRestorers = [];
let promiseLib;
Expand Down
4 changes: 2 additions & 2 deletions test/sandbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,7 @@ describe("Sandbox", function () {
}

const fn = async () => {
const sinonSandbox = sinon.createSandbox();
const sinonSandbox = createSandbox();

const f = new F();

Expand All @@ -2422,7 +2422,7 @@ describe("Sandbox", function () {
assert(b.calledImmediatelyBefore(c));
};

await Promise.all([fn, fn, fn]);
await Promise.all([fn(), fn(), fn(), fn()]);
});
});
});

0 comments on commit fabf95c

Please sign in to comment.