Conversation
cjihrig
left a comment
There was a problem hiding this comment.
LGTM with a few suggestions. I think this is a useful change (helping with code coverage in modules using assert, and improving error types).
doc/api/assert.md
Outdated
test/parallel/test-assert.js
Outdated
There was a problem hiding this comment.
If you store the RangeError in a variable, you can just assert that e equals it.
test/parallel/test-assert.js
Outdated
There was a problem hiding this comment.
For these tests involving try...catch, we don't know if the assertions were actually run. Can you add checks like these
doc/api/assert.md
Outdated
|
@cjihrig @vsemozhetbyt thanks for the feedback... updated! |
BridgeAR
left a comment
There was a problem hiding this comment.
In general I like the idea a lot!
LGTM but I think it would be nice to use common.expectsError
| threw = true; | ||
| assert.ok(e instanceof RangeError, 'Incorrect error type thrown'); | ||
| } | ||
| assert.ok(threw); |
There was a problem hiding this comment.
It would actually be nice to use common.expectsError here. The test would be smaller in that case. You can check some other use cases as a reference.
There was a problem hiding this comment.
Thank you for the suggestion. I tried expectsError, but for this simple case it didn't make the code any cleaner/shorter/simpler. I'm keeping it as is for now.
|
Landed in e13d1df. Thanks! |
This commit adds special handling of Error instances when passed as the message argument to assert functions. With this commit, if an Error is passed as the message, then that Error is thrown instead of an AssertionError. PR-URL: #15304 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
|
I like the concept of this PR, but I think it was rushed.
(I'm not saying it should be reverted, but I do suggest we tweak it a bit before 9.0.0) |
|
@refack, definitely my bad on item 1. I apologize for that. Regarding item 2, that is how the surrounding tests in that file are written, so I don't necessarily think that is wrong. Maybe that could be a good first contribution. I don't really have any comment on item 3 other than the PR being open sufficiently long enough.
Do you want to submit a follow up PR? Again, my apologies for item 1. |
I totally agree there's nothing bad in this PR (on the contrary, I see it's usufulness). |
This commit adds special handling of Error instances when passed as the message argument to assert functions. With this commit, if an Error is passed as the message, then that Error is thrown instead of an AssertionError. PR-URL: nodejs#15304 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
assert - support a way to provide a custom Error type for assertions. This will help make assert more useful for validating types and ranges.