发现以下关于如何在 express 中测试中间件的提示:
https
://github.com/visionmedia/express/blob/master/test/req.xhr.js我想知道为什么我的测试总是通过。直到我注意到当我从 express 复制测试时,它们的行为相同。我试着把它们搞砸,但它们一直在通过:
https
://github.com/visionmedia/express/blob/master/test/req.xhr.js
我在这里错过了什么?
it('should return true when X-Requested-With is xmlhttprequest', function(done){
var app = express();
app.use(function(req, res){
req.xhr.should.be.false; //set to false, to fail the test but it still passes
res.end();
});
request(app)
.get('/')
.set('X-Requested-With', 'xmlhttprequest')
.end(function(res){
done();
})
})