I would like to know how to stop the console from printing stack dumps on test with promises that throw errors.
doCallTest = function() {
var p = new Promise(function(resolve, reject) {
reject(new Error('Nooooo'));
}).catch(function(err) {
throw new Error(err);
});
return Promise.delay(100).return(p);
};
// This prints error message `Error: Nooooo` and stack dump and halts the test
return expect(doCallTest()).to.eventually.be.rejectedWith('Nooooo');
I see a lot of mentions of similar sounding issues but not sure how to resolve it. There is Bluebird.onPossiblyUnhandledRejection
but that is just messy:
var P = require('bluebird');
P.onPossiblyUnhandledRejection(function(error){
expect(error.message).to.be.eql('Nooooo');
done();
});
doCallTest();
How can I make use of Chai's thrown error tests with promises?
Edit I've narrowed it down to the delay() call. Removing that makes it work fine.
Perhaps related: https://github.com/petkaantonov/bluebird/issues/100
Update The issue seems to have been because of my use of delay()
as:
return Promise.delay(100).return(p);
Instead of:
return p.delay(100);
The latter had not worked for me initially which is why I changed it - I suspect it was becasue of how my catch calls were setup. By changing things around I was able to use the latter format:
doCallTest = function() {
var p = new Promise(function(resolve, reject) {
reject(new Error('Nooooo'));
});
return p.delay(100);
};