Skip to content

Rule proposal: prefer-t-throws #156

Description

@gajus

Issuehunt badges

I was reviewing some codes using ava and found this pattern repeating often:

try {
  await request(requestOptions);
} catch (error) {
  t.true(error.statusCode === 500);
}

This can be written instead as:

const error = await t.throws(request(requestOptions));

t.true(error.statusCode === 500);

I think the latter should be preferred.


IssueHunt Summary

sindresorhus sindresorhus has been rewarded.

Backers (Total: $82.00)

Submitted pull Requests


Tips

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