【发布时间】:2020-06-06 09:33:10
【问题描述】:
我正在使用 Superagent(通过 Async/Await 处理 Promise)并希望对 Chai 的 Expect 响应做一些额外的断言。问题是当响应断言需要任何异步操作时,我们无法以响应断言格式执行它,例如:
it('should check for something on response', async () => {
await superagent(app)
.expect(200)
.expect(res => {
chai.expect(res.body).to.have.property('something')
})
})
所以在上面添加异步断言就像:
it('should check for something async on response', async () => {
await superagent(app)
.expect(200)
.expect(async res => {
chai.expect(await checkForSmth(res.body)).to.be.true
})
})
哪个不起作用并且总是通过,当测试失败时会导致未处理的 Promise 拒绝警告!
【问题讨论】:
标签: javascript testing bdd chai supertest