deps: body-parser@1.20.0
[express.git] / test / req.xhr.js
blob99cf7f1917dec4b06b2028e7aa1ac3d0a73cc2cf
1 'use strict'
3 var express = require('../')
4   , request = require('supertest');
6 describe('req', function(){
7   describe('.xhr', function(){
8     before(function () {
9       this.app = express()
10       this.app.get('/', function (req, res) {
11         res.send(req.xhr)
12       })
13     })
15     it('should return true when X-Requested-With is xmlhttprequest', function(done){
16       request(this.app)
17         .get('/')
18         .set('X-Requested-With', 'xmlhttprequest')
19         .expect(200, 'true', done)
20     })
22     it('should case-insensitive', function(done){
23       request(this.app)
24         .get('/')
25         .set('X-Requested-With', 'XMLHttpRequest')
26         .expect(200, 'true', done)
27     })
29     it('should return false otherwise', function(done){
30       request(this.app)
31         .get('/')
32         .set('X-Requested-With', 'blahblah')
33         .expect(200, 'false', done)
34     })
36     it('should return false when not present', function(done){
37       request(this.app)
38         .get('/')
39         .expect(200, 'false', done)
40     })
41   })