【发布时间】:2018-12-26 15:08:37
【问题描述】:
我有一些 mocha/chai/chai-http 测试遵循以下结构,但是每当一个测试失败时,我都会得到一个 UnhandledPromiseRejectionWarning,我似乎无法弄清楚它的来源。
UnhandledPromiseRejectionWarning:未处理的承诺拒绝。这 错误源于在异步函数内部抛出 没有 catch 块,或拒绝未处理的承诺 使用 .catch()。
describe('indexData', () =>{
it('Should return status code 200 and body on valid request', done => {
chai.request(app).get('/api/feed/indexData')
.query({
topN: 30,
count: _.random(1, 3),
frequency: 'day'
})
.set('Authorization', token).then(response => {
// purposefully changed this to 300 so the test fails
expect(response.statusCode).to.equal(300)
expect(response.body).to.not.eql({})
done()
})
})
})
我尝试在.then() 之后添加.catch(err => Promise.reject(err),但它也不起作用。我可以在这里做什么?
【问题讨论】:
标签: node.js mocha.js chai chai-http