Feature request: suppressUnhandledRejections return promise instance
See original GitHub issue(This issue tracker is only for bug reports or feature requests, if this is neither, please choose appropriate channel from http://bluebirdjs.com/docs/support.html)
Please answer the questions the best you can:
- What version of bluebird is the issue happening on?
3.x
- What platform and version? (For example Node.js 0.12 or Google Chrome 32)
all
- Did this issue happen with earlier version of bluebird?
N/A (feature request)
(Write description of your issue here, stack traces from errors and code that reproduces the issue are helpful)
I would like to suggest an API change (semver major) to have .suppressUnhandledRejections()
return the existing promise instance, allowing chained calls such as:
return Bluebird.reject(new Error('ouch')).suppressUnhandledRejections()
This is a pattern I use a lot in my unit tests where I want to prepare a rejection, then run the code under test, inject the rejected promise into the code path via mock/stub (sinon, testdouble, etc), then the code under test attaches its rejection handlers, and finally the test code path completes. Currently I need a separate helper method to avoid bluebird printing errors about potentially unhandled rejections.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7
The problem with this suggestion is that you might get warnings in dev/prod that you did not get in tests. If you actually do have an error in the function which causes a warning to be generated, using the suppression feature this way in the test doubles will turn that warning off during testing - which is probably not what you want.
The suggestion itself seems okay, just not sure about the use case…
Great! I verified
.thenDo(() => Bluebird.reject(down))
seems to work with no warnings. Thanks! Leave this open for discussion as this fact seems unrelated to the feature request here, but my immediate needs are solved so feel free to close this if no one else thinks it would be useful.