0
所以我有一個節點模塊,如:單元測試/懲戒貓鼬型號興農
let mongoose = require('mongoose'),
User = mongoose.model('User');
module.exports = (req, res, next) => {
User.findById(req.user)
.then(user => {
req.body.user = user._id;
req.body.company = user.company;
next();
}, err => {
req.send(400, err);
});
};
因此,在這種情況下,我想,以確保正確的東西附着在req.body
。那麼,我該如何去嘲弄User
函數呢?我必須首先加載模型,以便在調用mongoose.model
之前,此代碼不會引發錯誤,因此可能與實際存根全球require
存根有關?感謝您的任何建議!