-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Closed
Labels
assertIssues and PRs related to the assert subsystem.Issues and PRs related to the assert subsystem.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.stale
Description
What is the problem this feature will solve?
I've been implementing some features on the assert module see #43133 and I figured that it's a bit confusing for users to use the signature:
callTracker.calls()
callTracker.calls(1)
callTracker.calls(fn)
callTracker.calls(fn, 1)
callTracker.callsWith(['arg1'])
callTracker.callsWith(fn, ['arg1'])
callTracker.callsWith(fn, ['arg1'], 1)
When looking at the intelliSense, it's also confusing because the calls signature is calls(fn, exact = 1)
however nether fn or exact are required fields so we have to check every positional argument see
node/lib/internal/assert/calltracker.js
Lines 38 to 57 in 71fc444
// When calls([arg1, arg2], ?1) | |
if (ArrayIsArray(fn)) { | |
exact = typeof withArgs === 'number' ? withArgs : exact; | |
withArgs = fn; | |
fn = noop; | |
} | |
// When calls(1) | |
if (typeof fn === 'number') { | |
exact = fn; | |
fn = noop; | |
} | |
// When calls() | |
if (fn === undefined) { | |
fn = noop; | |
} | |
// Else calls(fn, 1, []) | |
validateUint32(exact, 'exact', true); |
What is the feature you are proposing to solve the problem?
I'd like to propose that we use object destructuring for those function signatures as it could improve the editor's intelliSense and readability:
callTracker.calls({
exact: 1,
fn: myFn
})
callTracker.callsWith({
withArgs: ['arg1']
})
What alternatives have you considered?
No response
Metadata
Metadata
Assignees
Labels
assertIssues and PRs related to the assert subsystem.Issues and PRs related to the assert subsystem.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.stale