【发布时间】:2017-10-16 16:07:59
【问题描述】:
我正在使用 Chai http 和 promise。下面的测试应该失败,但它没有调用 then 函数就通过了。如果我添加 done 参数以等待异步函数完成,它会失败(正确)。我做错了吗?
it('Returns the correct amount of events', function() {
chai.request(app)
.get('/api/events/count')
.then(function(res) {
throw new Error('why no throw?');
expect(res).to.have.status(200);
expect(res).to.be.json;
})
.catch(function(err) {
throw err;
});
});
【问题讨论】: