From 801a1791d61fe5ac488e303ad2f4dcbb20b5490d Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Tue, 8 Nov 2011 20:28:06 -0800 Subject: [PATCH] Added req.xhr tests --- test/req.xhr.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/req.xhr.js diff --git a/test/req.xhr.js b/test/req.xhr.js new file mode 100644 index 00000000..8df7b4a0 --- /dev/null +++ b/test/req.xhr.js @@ -0,0 +1,54 @@ + +var express = require('../') + , request = require('./support/http'); + +describe('req', function(){ + describe('.xhr', function(){ + it('should return true when X-Requested-With is xmlhttprequest', function(done){ + var app = express(); + + app.use(function(req, res){ + req.xhr.should.be.true; + res.end(); + }); + + request(app) + .get('/') + .set('X-Requested-With', 'xmlhttprequest') + .end(function(res){ + done(); + }) + }) + + it('should return false otherwise', function(done){ + var app = express(); + + app.use(function(req, res){ + req.xhr.should.be.false; + res.end(); + }); + + request(app) + .get('/') + .set('X-Requested-With', 'blahblah') + .end(function(res){ + done(); + }) + }) + + it('should return false when not present', function(done){ + var app = express(); + + app.use(function(req, res){ + req.xhr.should.be.false; + res.end(); + }); + + request(app) + .get('/') + .end(function(res){ + done(); + }) + }) + }) +})