-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Errors in Async aren't caught correctly #2785
Comments
If your promise is swallowing the exceptions because it does not use ...Except that Mocha could do a better job of reporting the problem, for which we have issue #2640. (Closing this as a duplicate of that, since that's the solution -- or the closest thing we can get to one anyway -- on Mocha's end.) For your specific case, however: I'm fairly sure* the third var controller = function (req, res, next) {
// NOTE: if multiple different `then`s are being called on the initial promise instead of on the returned promise from prior `then`s, the `catch` would need to be added to the returned promise from each of those branches. I'm not sure if that comes up or not, based on the intermediate variable that's only used once in the example.
new Promise(function(resolve) {
setTimeout(resolve);
}).then(function () {
res.redirect('/otherPath');
}).catch(next);
}; ...and then just change the Mocha test to give the controller controller({}, res, done); *(Let me know if this doesn't actually work -- I'm sketching it out from memory as I haven't had to use explicit error handling in a non-error Express route handler recently.) |
This feels very similar to #1128, however, that solution was helped along with promises. I can't find a way to solve this with promises. My specific example is when I'm testing an Express.js controller:
There is a promise involved which causes the mocha test runner to lose context, however, the promise happens in the controller, then resolves through a callback.
Here it is in JSFiddle... https://jsfiddle.net/ccwapndu/ (ProTip: open the console)
The text was updated successfully, but these errors were encountered: