Skip to content
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

fix(testing): assertThrowsAsync always reporting Error instead of actual error class #1051

Merged
merged 2 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testing/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ export async function assertThrowsAsync<T = void>(
}
if (ErrorClass && !(e instanceof ErrorClass)) {
msg =
`Expected error to be instance of "${ErrorClass.name}", but got "${e.name}"${
`Expected error to be instance of "${ErrorClass.name}", but was "${e.constructor.name}"${
msg ? `: ${msg}` : "."
}`;
throw new AssertionError(msg);
Expand Down
15 changes: 15 additions & 0 deletions testing/asserts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,3 +1039,18 @@ Deno.test("Assert Throws Async Parent Error", () => {
"Fail!",
);
});

Deno.test("Assert Throws Async promise rejected with custom Error", async () => {
class CustomError extends Error {}
class AnotherCustomError extends Error {}
await assertThrowsAsync(
() =>
assertThrowsAsync(
() => Promise.reject(new AnotherCustomError("failed")),
CustomError,
"fail",
),
AssertionError,
'Expected error to be instance of "CustomError", but was "AnotherCustomError".',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kt3k (I know this is already merged, but...)

Is there a convention for grammar in error messages?

For example, things like:

  • terminating punctuation vs no terminating punctuation:
    • "File not found."
    • "File not found"
  • conventional verbs (i.e. got/saw/was/etc.)
    • "Expected x but saw y"
    • "Expected x but got y"
  • etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsejcksn I don't think we have an explicit rule about it. But I think we should have one. Suggestions are welcome

);
});