Tag: 中国

如何在Express中模拟中间件跳过unit testing的身份validation?

Express中有以下内容 //index.js var service = require('./subscription.service'); var auth = require('../auth/auth.service'); var router = express.Router(); router.post('/sync', auth.isAuthenticated, service.synchronise); module.exports = router; 我想覆盖或模拟isAuthenticated返回这个 auth.isAuthenticated = function(req, res, next) { return next(); } 这是我的unit testing: it('it should return a 200 response', function(done) { //proxyquire here? request(app).post('/subscriptions/sync') .set('Authorization','Bearer '+ authToken) .send({receipt: newSubscriptionReceipt }) .expect(200,done); }); 我试过使用proxyquire嘲笑index.js – 我想我需要存根路由器? 我也尝试在testing中覆盖 […]