Testando a promessa rejeitada em Mocha / Chai
Eu tenho uma classe que rejeita uma promessa:
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;
});
};
No meu teste:
return expect(s.sendNote(data)).to.eventually.be.rejectedWith('Boo');
No entanto, enquanto o teste passa, ele lança o erro no console.
Erro de rejeição sem tratamento: ...
Com erros não prometidos, usei o bind para testar para impedir que o erro fosse lançado até que Chai pudesse quebrar e testar:
return expect(s.sendNote.bind(s, data)).to.eventually.be.rejectedWith('Boo');
No entanto, isso não funciona com isso e retorna:
TypeError:[Function] is not a thenable.
Qual é a maneira correta de testar isso?