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

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

merged 2 commits into from
Jul 26, 2021

Conversation

lowlighter
Copy link
Contributor

@lowlighter lowlighter commented Jul 21, 2021

Closes #967

As assertThrowsAsync has an implementation drift from assertThrows which result in hiding the actual typing of errors in result messages when using custom errors:

class CustomError extends Error {}
Deno.test("test", async () => void await assertThrowsAsync(() => Promise.reject(new CustomError()), TypeError))

Before (making test harder to debug):

AssertionError: Expected error to be instance of "TypeError", but got "Error".

After:

AssertionError: Expected error to be instance of "TypeError", but got "CustomError ".

References:

AssertThrows:
https://github.com/denoland/deno_std/blob/e4c6419c466335eb697df38a387a2def06e6f3c5/testing/asserts.ts#L598

AssertThrowsAsync:
https://github.com/denoland/deno_std/blob/e4c6419c466335eb697df38a387a2def06e6f3c5/testing/asserts.ts#L644

@lowlighter lowlighter changed the title fix: assertThrowsAsync always reporting Error instead of ErrorClass fix(testing): assertThrowsAsync always reporting Error instead of actual error class Jul 22, 2021
@bartlomieju
Copy link
Member

@lowlighter the fix looks good, could you exercise this change in testing/asserts_test.ts and check that the returned message is as expected?

"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

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

@lowlighter Thank you for your contribution! LGTM

@kt3k kt3k merged commit 7c4017f into denoland:main Jul 26, 2021
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

Successfully merging this pull request may close these issues.

assertThrowsAsync inconsistent with assertThrows, error message shows wrong actual error class
4 participants