-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
assert: respect assert.doesNotThrow message. #2407
assert: respect assert.doesNotThrow message. #2407
Conversation
Would you mind fixing up the docs for
|
Good point, I'll update them. |
@diversario ... is this still something you'd like to pursue? |
I would; I actually asked a question here about it because I'm not quite sure how to proceed. |
@nodejs/ctc ... any thoughts on this one? |
I thought |
@cjihrig good point... does that only include API changes or also behavioral fixes like this one? |
I would have to go back and look at the CTC meeting notes, but I thought the idea was to only take patches that were relevant to Node's tests. |
I thought we would still accept actual bug fixes just not new features? |
I'm cool with fixing actual bugs. |
if (!shouldThrow && | ||
actual instanceof Error && | ||
typeof message === 'string' && | ||
expectedException(actual, expected) || |
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'd prefer to see a more liberal use of parens to make it explicit what the evaluation order is that you're using here, mixing &&
and ||
without parens makes this very difficult to parse. The number of conditions in here adds to that difficulty and it'd be nice to reduce it with some compacting variables—although not essential, just would be nice to make this less terse.
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.
Breaking out the ||
part into a var sounds good.
I'm fine with fixing bugs like this |
@diversario ... still interested in this? |
Oof... Is this still relevant? It's been so long. If it's still OK to go to master and there's no further PR feedback I can make the change @rvagg suggested and push up. |
@diversario ... yeah, still relevant. Just needs updated per @rvagg's comments and a couple of review sign offs. |
Pushed an update. |
@@ -51,7 +51,7 @@ Tests for deep inequality. Opposite of `assert.deepStrictEqual`. | |||
## assert.throws(block[, error][, message]) | |||
|
|||
Expects `block` to throw an error. `error` can be constructor, `RegExp` or | |||
validation function. | |||
validation function. When assertion fails, `message` will be included in the `AssertionError` message. |
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.
Can you line wrap these so each line is <= 80
Generally LGTM with a few nits |
Thanks for the feedback! I tried the ES6 syntax but I get a syntax error; I think this branch is off an old master that didn't have support for that yet. |
Can you rebase and update? |
Addresses nodejs#2385. Special handling to detect when user has supplied a custom message. Added a test for user message. When testing if `actual` value is an error use `util.isError` instead of `instanceof`.
Addresses nodejs#2407. Break out conditional into named variables for readability. Explain the purpose of `message` in throws/doesNotThrow assertions.
Landed in c1d82ac |
@jasnell lts? |
Yes
|
Special handling to detect when user has supplied a custom message. Added a test for user message. When testing if `actual` value is an error use `util.isError` instead of `instanceof`. Fixes: nodejs#2385 PR-URL: nodejs#2407 Reviewed-By: James M Snell <jasnell@gmail.com>
@@ -330,7 +330,14 @@ function _throws(shouldThrow, block, expected, message) { | |||
fail(actual, expected, 'Missing expected exception' + message); | |||
} | |||
|
|||
if (!shouldThrow && expectedException(actual, expected)) { | |||
const userProvidedMessage = typeof message === 'string'; |
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.
A year late to the party here but won't this always evaluate to true
since message
is forced into a string 7 lines up (line 326)?
ping @diversario, @jasnell
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.
Just because I stumbled upon this comment right now: this is fixed in newer versions.
Addresses #2385.
Special handling to detect when user has supplied a custom message.
Added a test for user message.
When testing if
actual
value is an error useutil.isError
instead ofinstanceof
.