【发布时间】:2025-11-22 21:30:01
【问题描述】:
我尝试用 mocha、supertest 和 sinon 测试这条快速路线。测试无法通过承诺,它在 User.find 回调函数中的第一次猫鼬调用后停止,并带有待处理的错误消息:
错误:超过 2000 毫秒的超时。确保在此测试中调用了 done() 回调。
我在回调中调用了 done() 但什么也没...
module.exports = function(app, User) {
app.route('/appointments')
.post(function(req,res){
User.find({'department': req.body.department}, function(err, workers){
return workers._id;
}).then(function(allWorkers){
var deferred = Q.defer();
function sortWorkers(worker){
return Appointments.find({worker: worker._id, start: req.body.date});
};
Q.all(_.map(allWorkers, sortWorkers)).done(function (val) {
deferred.resolve(val);
});
return deferred.promise;
}).then(function(workers){
console.log(workers);
})
.catch(function(error) {
console.log(error);
})
.done();
})
};
这是我的开始测试:
it("should save a user and not save the same", function(done){
var appointments = new Appointments({title: 'okok',worker: '580359c86f7159e767db16a9',start:'2015-04-08T02:50:04.252Z' ,department: 95});
console.log('appointments',appointments);
request(app)
.post("/appointments")
.send(appointments)
.expect(200)
.end(function(err,res){
console.log('ok',res);
done();
});
});
【问题讨论】:
标签: node.js mongoose promise mocha.js sinon