Skip to content

Commit 341a56c

Browse files
committed
assert: fix CallTracker calls wraps the function causes the original length to be lost
1 parent 17826f5 commit 341a56c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/internal/assert/calltracker.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
ArrayPrototypePush,
55
Error,
66
FunctionPrototype,
7+
ObjectDefineProperty,
78
ReflectApply,
89
SafeSet,
910
} = primordials;
@@ -46,7 +47,7 @@ class CallTracker {
4647
const callChecks = this.#callChecks;
4748
callChecks.add(context);
4849

49-
return function() {
50+
function callsFn() {
5051
context.actual++;
5152
if (context.actual === context.exact) {
5253
// Once function has reached its call count remove it from
@@ -59,7 +60,13 @@ class CallTracker {
5960
callChecks.add(context);
6061
}
6162
return ReflectApply(fn, this, arguments);
62-
};
63+
}
64+
65+
ObjectDefineProperty(callsFn, 'length', {
66+
value: fn.length
67+
});
68+
69+
return callsFn;
6370
}
6471

6572
report() {

test/parallel/test-assert-calltracker-calls.js

+14
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,17 @@ assert.throws(
7878
callsNoop();
7979
tracker.verify();
8080
}
81+
82+
{
83+
function func() {}
84+
const tracker = new assert.CallTracker();
85+
const callsfunc = tracker.calls(func);
86+
assert.strictEqual(func.length, callsfunc.length);
87+
}
88+
89+
{
90+
function func(a, b, c = 2) {}
91+
const tracker = new assert.CallTracker();
92+
const callsfunc = tracker.calls(func);
93+
assert.strictEqual(func.length, callsfunc.length);
94+
}

0 commit comments

Comments
 (0)