【发布时间】:2017-03-26 14:23:37
【问题描述】:
我正在使用mocha 针对外部 Web 服务运行大量集成测试。我使用superagent-promise 进行请求/响应处理,我使用expect 作为我的断言库。
对于其中一些测试,我需要将大量请求链接在一起,因此这些承诺非常有帮助。但是我注意到我的测试现在因超时(并且没有错误消息)而不是错误消息本身而失败。举个简单的例子:
it('[MESSAGES-1] cannot be posted without an auth token', function(done) {
agent.post(config.webRoot + '/rooms/ABC/messages').send({
content: 'This is a test!'
}).end().then(function(res) {
// Not expected
}, function(err) {
expect(err.status).toBe(401)
done()
})
})
按预期工作并通过:
Messages
✓ [MESSAGES-1] cannot be posted without an auth token
但是如果我改变我的断言以期望不同的状态码:
expect(err.status).toBe(200) // This should fail
然后测试失败并超时!
1) Messages [MESSAGES-1] cannot be posted without an auth token:
Error: timeout of 1000ms exceeded. Ensure the done() callback is being called in this test.
这是一个常见问题吗?有没有我可以做的解决方法或调整?我不想失去使用 Promise 的能力。
【问题讨论】:
标签: javascript promise mocha.js superagent