I have a class that rejects a promise:
Sync.prototype.doCall = function(verb, method, data) {
var self = this;
self.client = P.promisifyAll(new Client());
var res = this.queue.then(function() {
return self.client.callAsync(verb, method, data)
.then(function(res) {
return;
})
.catch(function(err) {
// This is what gets called in my test
return P.reject('Boo');
});
});
this.queue = res.delay(this.options.throttle * 1000);
return res;
};
Sync.prototype.sendNote = function(data) {
var self = this;
return self.doCall('POST', '/Invoice', {
Invoice: data
}).then(function(res) {
return data;
});
};
In my test:
return expect(s.sendNote(data)).to.eventually.be.rejectedWith('Boo');
However while the test passes it throws the error to the console.
Unhandled rejection Error: Boo ...
With non promise errors I have used bind to test to prevent the error from being thrown until Chai could wrap and test:
return expect(s.sendNote.bind(s, data)).to.eventually.be.rejectedWith('Boo');
However this does not work with this and returns:
TypeError: [Function] is not a thenable.
What is the correct way to test for this?