unit testing express route with async callback
问题 I'm writing an app in node.js using express. I seperated the route definition from express so I will be able to unit test it without mocking out express. What I did is: file: usersRoutes.js var routes = { getAll: function(req,res) { var db = req.db; // req.db is initialized through a dedicated middleware function var usersCollection = db.get('users'); usersCollection.find({},{limit:10},function(e,results){ res.send(results); }); } }; module.exports = routes; file: users.js var express =