Jac*_* Ye 6 mocha.js node.js express supertest es6-promise
假设我有一些控制器逻辑:
// registered for route POST /login
function login(req, res, next) {
User.findOne({username: req.body.username}).exec()
.then(user => {
if (user) {
return bcrypt.compareAsync(req.body.password, user.password)
} else {
throw new APIError("Unauthorized", 401)
}
})
.then(some more chained promises)
.catch(next)
}
Run Code Online (Sandbox Code Playgroud)
但是当在控制器中测试悲伤路径时,它总是给出超时错误:
it('throws unauthorized error if no user match', () => {
return request(app)
.post('/login')
.send({ username: 'notExistInDB', password: 'asdfasd'})
.expect(401)
})
Run Code Online (Sandbox Code Playgroud)
此测试失败并显示错误消息:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经尝试过但没有成功的事情:
done()回调而不是返回 Supertest 承诺如果您对可能出现的问题有任何线索,请提供帮助。这真的让我很烦恼,因为我无法测试控制器中的任何悲伤路径,并且当测试失败时我永远看不到实际的错误。
| 归档时间: |
|
| 查看次数: |
666 次 |
| 最近记录: |