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

test: proposal common.expectsError nextTick option #29749

Description

@ronag

I would like to propose a new option for common.expectsError which will indicate whether the error can be invoked in the same tick or not, e.g.

I would like to be able to replace tests like this:

let ticked = false;
stream.write(null, common.mustCall((err) => {
  assert.strictEqual(ticked, true);
  common.expectsError(opts)(err);
}));
ticked = true;

with

stream.write(null, common.expectsError({
 ...opts,
 nextTick: true
});

Would this make sense? It's quite often that one wants to test for callback errors and that they should be invoked asynchronously.

I think this would also help us actually making sure that callbacks are invoked asynchronously.

NOTE: Can I use expectsError to test for no error?

Activity

  1. changed the title [-]test: proposal common.expectsError tick[/-] [+]test: proposal common.expectsError nextTick option[/+] on Sep 28, 2019
  2. Trott commented on Sep 28, 2019

    @Trott
    Member

    I (probably) wouldn't block it, but I think the first example is clear. I think the proposed API results in code where it is not immediately obvious what is going on. So someone will have to go and read the documentation, which increases friction.

    If anything, in the first example, I might avoid common.expectsError() and use one or more calls to assert.strictEqual() instead. The test code will be longer, but it will be clearer. No one will have to learn our common.expectsError() function to understand the test.

  3. cjihrig commented on Sep 28, 2019

    @cjihrig
    Contributor

    I share @Trott's opinion on this issue.

    I'd actually like to see common.expectsError() go away completely, but that's not the topic of this issue 😄

  4. ronag commented on Sep 28, 2019

    @ronag
    MemberAuthor

    Makes sense.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions