I want to make an assertion in a catch block of a promise chain, but it reaches the timeout. Assertions work in then blocks, but it seems in the catch block, done() is never reached. Is it being suppressed? Is there a better way to test promise rejections?
import assert from 'assert';
import { apicall } from '../lib/remoteapi';
describe('API calls', function () {
it('should test remote api calls', function (done) {
apicall([])
.then((data) => {
assert.equal(data.items.length, 2); // this works fine
done();
})
.catch((e) => {
console.log('e', e);
assert.equal(e, 'empty array'); // ?
done(); // not reached?
});
});
});
The promise rejection
apicall(channelIds) {
if(channelIds.length === 0) return Promise.reject('empty array');
...
}
I get this error:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
Aucun commentaire:
Enregistrer un commentaire