Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gajus opened this issue Apr 18, 2017 · 1 comment
Closed

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

gajus opened this issue Apr 18, 2017 · 1 comment

Comments

@gajus
Copy link

gajus commented Apr 18, 2017

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.

@gajus gajus changed the title Provide a convenience syntax for testing error constructor and message Provide a convenience API for testing error constructor and message Apr 18, 2017
@sindresorhus
Copy link
Member

sindresorhus commented Apr 19, 2017

Duplicate of #1047. I agree it's currently sub-optimal. You should be able to assert the different specifics of an error in one assertion. See my proposal #1047 (comment) and add your thoughts there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants