-
Notifications
You must be signed in to change notification settings - Fork 30k
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: async parameter for assert.throws() and assert.doesNotThrow() #17843
Conversation
The function given to assert.trows() and assert.doesNotThrow() can be an async (or return a promise)
No opinion (yet) one way or the other, but it does seem to break this test case which you probably want to fix?:
(This test it in |
Hi @feugy! Welcome and thanks for the pull request. This may be obvious, but do be patient given the time of year. Lots of folks might not be available for another week or maybe even longer. Meanwhile, I'll @-mention @BridgeAR to get their attention (since they've been working on |
Thanks for the pull request, @feugy! My initial feeling is that making I'm guessing this also presents a significant regression for the benchmark at This is also further complicated by a scenario where the function passed in is supposed to return a Promise and the end-user have no expectation of |
This is a very hard breaking change because no error will be thrown sync anymore. As far as I see it, it is not possible to implement this as requested. The only possibility I see is adding a new function with this functionality. I would be fine with that (the name should indicate that it is async in this case, since all assert functions are sync). Theoretically we could check if the input is a promise and special handle that but this would not only also be a hard breaking change, it would also release Zalgo. |
Hi gents! Thank you so much for the feedback. I wasn't expecting such quick answer. It is definitely better to provide distinct functions. I'll do it if you guys think this feature could be handy. |
While moving to a promises-based API is generally the right thing, doing it this way is the wrong approach. Rather than modifying the existing methods (and breaking existing code), new async methods should be exposed. See #17739 for an example. |
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.
Making the objection on this explicit for the time being.
@feugy do not worry. Thanks a lot for the suggestion. I recommend to open a new PR that adds the new functions. I am closing this due to the expressed issues. |
Hello community!
It's my first PR, I hope I didn't missed important stuff.
Documentation isn't included yet as I'd like to get feedback on this new feature first.
The first parameter of
assert.throws()
andassert.doesNotThrow()
can be an async function.Benefit is to make tests way more easier to read.
Validating error behaviour with promise-based code used to look like this:
Now, thanks to async/await support, it looks like this:
With native async support, it can now be written like this:
However, it may be considered as a breaking change:
assert.throws()
used to return nothing, while now, due to its async nature, it returns a Promise.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
assert