镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

assert: change callTracker.calls and callTracker.callsWith to use an object param instead of positional params #43161

Closed

Description

@ErickWendel

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

// 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

Activity

  1. added
    assertIssues and PRs related to the assert subsystem.
    on May 20, 2022
  2. Trott commented on May 20, 2022

    @Trott
    Member

    @nodejs/assert @nodejs/testing

  3. Trott commented on May 20, 2022

    @Trott
    Member

    I'm not super-familiar with this API, but the suggestion for calls() to be calls(options) makes sense to me. For callsWith(), I wonder if we want callsWith(args, options).

  4. ErickWendel commented on May 21, 2022

    @ErickWendel
    MemberAuthor

    I'm not super-familiar with this API, but the suggestion for calls() to be calls(options) makes sense to me. For callsWith(), I wonder if we want callsWith(args, options).

    I liked it! both calls(options) and callsWith(args, options) 🤩

    Should I implement it?

  5. ErickWendel commented on Jun 6, 2022

    @ErickWendel
    MemberAuthor

    Should I? 😬

  6. jasnell commented on Jun 6, 2022

    @jasnell
    Member

    I'd say go ahead

  7. moved this to Pending Triage in Node.js feature requestson Oct 22, 2022
  8. github-actions commented on Dec 4, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  9. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Dec 4, 2022
  10. moved this from Pending Triage to Stale in Node.js feature requestson Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    assertIssues and PRs related to the assert subsystem.feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions