Prueba de promesa rechazada en Mocha / Chai
Tengo una clase que rechaza una promesa:
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;
});
};
En mi prueba:
return expect(s.sendNote(data)).to.eventually.be.rejectedWith('Boo');
Sin embargo, mientras la prueba pasa, arroja el error a la consola.
Error de rechazo no controlado: Boo ...
Con errores no prometedores, he usado bind para probar para evitar que se produzca el error hasta que Chai pueda ajustar y probar:
return expect(s.sendNote.bind(s, data)).to.eventually.be.rejectedWith('Boo');
Sin embargo, esto no funciona con esto y devuelve:
Error de tecleado:[Function] is not a thenable.
¿Cuál es la forma correcta de probar esto?