Skip to content

[Feature Request] Implement assert.rejects() and assert.doesNotReject() #272

Description

@nev21

Feature Request

Add async/Promise assertion functions to match Node.js assert API.

Missing Functions

  • assert.rejects(asyncFn, error?, message?) - Awaits the asyncFn promise or, if asyncFn is a function, calls the function and awaits the returned promise. It will then check that the promise is rejected.
  • assert.doesNotReject(asyncFn, error?, message?) - Awaits the asyncFn promise or, if asyncFn is a function, calls the function and awaits the returned promise. It will then check that the promise is not rejected.

Current Workarounds

// Instead of assert.rejects()
await assert.throws(async () => await asyncFn());

// Instead of assert.doesNotReject()
await assert.doesNotThrow(async () => await asyncFn());

Node.js Documentation

Related

See migration guide: Migrating from Node.js Assert

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions