Skip to content

Provide a convenience API for testing error constructor and message #1362

Closed
@gajus

Description

@gajus

Description

The current API:

.throws(function|promise, [error, [message]])

only allows to define constructor of the error and requires to test message separately, e.g.

const error = await t.throws(createReservation(undefined, parameters, context), UserError);

t.true(error.message === 'Ticket selection cannot be empty.');

By the way, .throws(function|promise, [error, [message]]) is slightly misleading.
At first I thought the third parameter is the error message, i.e.
t.throws(createReservation(undefined, parameters, context), 'Ticket selection cannot be empty.');.

It would be convenient to be able to construct the error as such:

await t.throws(createReservation(undefined, parameters, context), new UserError(Ticket selection cannot be empty.));

In such case, ava would need to check that the constructor of the object and the message match.

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