-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
question: best practice for handling unexpected err
in tests
#13115
Comments
/cc @nodejs/testing |
I think what you wrote above is a pretty good summary. Some stuff may have changed, I'm not sure, but you probably know because you're probably the person that would have changed it :-D If you think it belongs in the test-writing guide, by all means, go for it. Lint rules might be feasible too, not sure to be honest. I'm going to close, but feel free to re-open if there's more to talk about. |
Yeah, time to turn this into action. |
master
Ref: #13092 (comment)
Do we have a better construct for handling
err
in callbacks:What I found that gives the most informative results (stack of exception and a frame for the test) are:
common.mustCall((err) => {if (err) assert.fail(err)})
.on('error')
handlers(err) => assert.fail(err)
That is the only way to get a frame in the stack.
regular callback
common.mustCall((err) => {if (err) assert.fail(err)})
with
common.mustCall((err) => {assert.ifError(err)})
or
common.mustCall(assert.ifError)
.on('error')
with
(err) => assert.fail(err)
with just
assert.fail
The text was updated successfully, but these errors were encountered: