mirror of
https://github.com/zebrajr/express.git
synced 2026-01-15 12:15:27 +00:00
Added req.xhr tests
This commit is contained in:
54
test/req.xhr.js
Normal file
54
test/req.xhr.js
Normal file
@@ -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();
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user