forked from expressjs/express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreq.get.js
59 lines (46 loc) · 1.36 KB
/
req.get.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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)
})
})
})