-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Better throws helper #1315
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
Merged
Merged
Better throws helper #1315
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a0bbb19
to
950e71d
Compare
0689f1c
to
ac348ff
Compare
sindresorhus
approved these changes
Mar 25, 2017
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I really like how extensive the t.throws
detection is now.
lib/assert.js
Outdated
@@ -17,6 +17,7 @@ class AssertionError extends Error { | |||
|
|||
this.assertion = opts.assertion; | |||
this.fixedSource = opts.fixedSource; | |||
this.improperUsage = opts.improperUsage || false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have gone with incorrect
instead of improper
, but not important.
If the source is known through other means it doesn't have to be derived from the assertion error's stack trace.
The formatted labels sometimes assume the context of the error message. And, since formatted values can be quite long, it's odd to see the message only at the very end.
ac348ff
to
132c887
Compare
Show instructions on how to use `t.throws()` with the test results, without writing them to stderr. Detect the improper usage even if user code swallows the error, meaning that tests will definitely fail. Assume that errors thrown, or emitted from an observable, or if the returned promise was rejected, that that error is due to the improper usage of `t.throws()`. Assume that if a test has a pending throws assertion, and an error leaks as an uncaught exception or an unhandled rejection, the error was thrown due to the pending throws assertion. Attribute it to the test.
132c887
to
5ce8038
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Integrate with avajs/babel-plugin-throws-helper#8. Again lead with some minor refactoring, though the repositioning of the error message is notable.
New output when improper usage of
t.throws()
is detected: