bluebird: bluebird logs out "unhandled rejection error" despite rejection being handled by chai-as-promised
I’m moving this issue from domenic/chai-as-promised#97 - we have a user (@ohjames) who is claiming that while using bluebird, and asserting with chai-as-promised that rejection has been handled, bluebird still believes the rejection has not been handled. To quote the OP:
I would have thought this mocha test would work fine:
// Either I've made a mistake or chai-as-promised is crap... it('finds that chai-as-promised is not broken', function() { var Promise = require('bluebird') var promise = Promise.reject(Error()) return promise.should.be.rejected })
It looks like it passes but check out the stderr after the test…
User Model ✓ finds that chai-as-promised is not broken Unhandled rejection Error at Error (native) at Context.<anonymous> (/home/mega-totoro/projects/cuddle-friends/server/api/user/user.model.spec.js:40:34) at callFn (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runnable.js:223:21) at Test.Runnable.run (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runnable.js:216:7) at Runner.runTest (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:374:10) at /home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:452:12 at next (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:299:14) at /home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:309:7 at next (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:247:23)
Or am I doing something stupid?
here is the LOC where chai-as-promised handles the rejection.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 6
- Comments: 31 (8 by maintainers)
Hah, well yeah, that’s fun.
Have retested it on both my computers now, and can’t reproduce it anymore either. Ran the test suite in our app, and it doesn’t happen there anymore either.
Guess we’ll file this under the Mulder & Scully category.
I’d recommend to simply use
I did this:
To make it more the sscce more reproducible, we added a delay between the declaration of the promise and the
should.be.rejected
.Does it makes it easier to solve the problem ?
How to fix this problem? Can we redirect the output of the console.log of the promise under test or redefine bluebird’s rejection handler?
@adamreisnz At the risk of saying “works on my machine”… well…
@petkaantonov @keithamus
Actually, that example fails for me if I include it inside of an actual test:
Put it inside a test file and run with Mocha:
./node_modules/mocha/bin/_mocha "test.spec.js"
Result:
Running it as a standalone script (without the
describe
andit
wrappers) didn’t trigger the error.I’m getting these Unhandled rejection errors in a lot of my tests now that used to work fine, so it seems something has happened/changed that this problem has now returned.
This happens with Node 7.1.0 and 7.2.0 for me. Any thoughts?
If you have single consumer scenario it makes no sense to divide the promise chains like above though. And if you have multiple consumers, then each consumer of course should handle their respective errors, in your case consumer 1 didn’t handle it but only consumer 2 did.