馃殌 Feature: Custom error message for failed await #4928
Labels
status: wontfix
typically a feature which won't be added, or a "bug" which is actually intended behavior
type: feature
enhancement proposal
Is your feature request related to a problem or a nice-to-have?? Please describe.
In a module I'm working on, I'm unit testing a scenario that involves very significant amounts of
Promise
chaining. Naturally, should the tested component break, the output I usually get is:This doesn't really give me much insight into why a Promise-chain test failed; I only get to know that it failed. I don't even get to see how much of the unit test completed before failing.
To be clear, I'm developing the
Promise
s that are being chained and tested, as well as the parts that are using these Promises.Describe the solution you'd like
The request: I'd like something similar to the following:
to produce the following failure log message on timeout:
Or at least something similar that provides much higher-quality information for diagnosing the test failure than the generic error above.
Setting
this.timeoutError = null
or= undefined
would clear the error object and set the default message back in place.I've opted for
this.timeoutError
in this proposal becausethis.timeout
already exists as a feature, so this should be easy enough to integrate with Mocha's existing design - the essential mechanics seem to be present already, withthis.timeout
's existing implementation serving as a useful guide.Describe alternatives you've considered
Of course, it's possible this may belong more in an assertion library of some sort... though I suspect an assertion library would actually need some sort of Mocha hook to connect with for the error report.
I'd love an assertion library to provide:
and provide a beautiful corresponding call stack for the failed await, complete with an
AssertionAsyncError
type/heading (rather than plainError
). This would even show the exact line of the test case's point-of-failure in the call stack. That said, I realize that this aspect - the custom assertion function - is better asked of assertion libraries likechai.js
than of Mocha.Either way, only getting a generic
Error: Timeout
message... doesn't provide me with much information on where the timeout error occurred within the Promise chain / heavilyasync
/await
-based unit test. A feature like this would provide much better feedback for such use cases.The greater context: I'm coding a custom gesture engine component for a project; this engine involves a processing stage which performs segmentation of the user's touchpath, with a goal of facilitating complex gesture types. Naturally, this segmentation happens live over time - gestures should feel responsive, after all - and thus involves quite a bit of asynchronous reasoning. I'm finding it important to test the ordering of Promise resolution so that I can provide guarantees on resolution order for its consumer(s).
The text was updated successfully, but these errors were encountered: