0
我正在使用supertest,摩卡和期待测试我的应用程序。我遇到了返回的文档为空并且没有错误的问题。Supertest猫鼬查询问题
router.get('/user', function (req, res) {
User.findOne({
_id: '56c59bb07a42e02d11a969ae'
}, function (err, user) {
if(err) return res.status(404).json({message: 'not found: ' + err.message});
res.status(200).json(user);
});
});
当我测试这对邮差我总是得到200这是我所期待的,但是当我运行测试,我得到404 :(
下面,我总是得到404
我简单的测试代码it('get user', function (done) {
request(app)
.get('/user')
.expect(200)
.end(function (err, res) {
if (err) throw err;
done();
});
});
两个邮差和测试指的是相同的猫鼬的数据库,所以我敢肯定,它应该能够获取用户。猫鼬和应用程序如何在我下面的服务器设置。
mongoose.connect('mongodb://localhost/scratch', options);
app.listen(port, function() {
console.log('Scratch started on port ' + port);
});
有什么我需要做的,以使其工作?