req.get.js
This file
Path
test/req.get.js
59 lines · 1.4 KiB · JavaScript
Last changed by
Improve error with invalid arguments to req.get()Douglas Christopher Wilsonbefore adoptionc762b16
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
var express = require('../') , request = require('supertest') , assert = require('assert');
describe('req', function(){ describe('.get(field)', function(){ it('should return the header field value', function(done){ var app = express();
app.use(function(req, res){ assert(req.get('Something-Else') === undefined); res.end(req.get('Content-Type')); });
request(app) .post('/') .set('Content-Type', 'application/json') .expect('application/json', done); })
it('should special-case Referer', function(done){ var app = express();
app.use(function(req, res){ res.end(req.get('Referer')); });
request(app) .post('/') .set('Referrer', 'http://foobar.com') .expect('http://foobar.com', done); })
it('should throw missing header name', function (done) { var app = express()
app.use(function (req, res) { res.end(req.get()) })
request(app) .get('/') .expect(500, /TypeError: name argument is required to req.get/, done) })
it('should throw for non-string header name', function (done) { var app = express()
app.use(function (req, res) { res.end(req.get(42)) })
request(app) .get('/') .expect(500, /TypeError: name must be a string to req.get/, done) }) })})