fix(deps)!: mime-types@^3.0.0 (#5882)
[express.git] / test / res.append.js
blob8f72598bf529b601a5d01d9bbf149a657f99fcd0
1 'use strict'
3 var assert = require('assert')
4 var express = require('..')
5 var request = require('supertest')
7 describe('res', function () {
8 describe('.append(field, val)', function () {
9 it('should append multiple headers', function (done) {
10 var app = express()
12 app.use(function (req, res, next) {
13 res.append('Set-Cookie', 'foo=bar')
14 next()
17 app.use(function (req, res) {
18 res.append('Set-Cookie', 'fizz=buzz')
19 res.end()
22 request(app)
23 .get('/')
24 .expect(200)
25 .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar', 'fizz=buzz']))
26 .end(done)
29 it('should accept array of values', function (done) {
30 var app = express()
32 app.use(function (req, res, next) {
33 res.append('Set-Cookie', ['foo=bar', 'fizz=buzz'])
34 res.end()
37 request(app)
38 .get('/')
39 .expect(200)
40 .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar', 'fizz=buzz']))
41 .end(done)
44 it('should get reset by res.set(field, val)', function (done) {
45 var app = express()
47 app.use(function (req, res, next) {
48 res.append('Set-Cookie', 'foo=bar')
49 res.append('Set-Cookie', 'fizz=buzz')
50 next()
53 app.use(function (req, res) {
54 res.set('Set-Cookie', 'pet=tobi')
55 res.end()
56 });
58 request(app)
59 .get('/')
60 .expect(200)
61 .expect(shouldHaveHeaderValues('Set-Cookie', ['pet=tobi']))
62 .end(done)
65 it('should work with res.set(field, val) first', function (done) {
66 var app = express()
68 app.use(function (req, res, next) {
69 res.set('Set-Cookie', 'foo=bar')
70 next()
73 app.use(function(req, res){
74 res.append('Set-Cookie', 'fizz=buzz')
75 res.end()
78 request(app)
79 .get('/')
80 .expect(200)
81 .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar', 'fizz=buzz']))
82 .end(done)
85 it('should work together with res.cookie', function (done) {
86 var app = express()
88 app.use(function (req, res, next) {
89 res.cookie('foo', 'bar')
90 next()
93 app.use(function (req, res) {
94 res.append('Set-Cookie', 'fizz=buzz')
95 res.end()
98 request(app)
99 .get('/')
100 .expect(200)
101 .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar; Path=/', 'fizz=buzz']))
102 .end(done)
107 function shouldHaveHeaderValues (key, values) {
108 return function (res) {
109 var headers = res.headers[key.toLowerCase()]
110 assert.ok(headers, 'should have header "' + key + '"')
111 assert.strictEqual(headers.length, values.length, 'should have ' + values.length + ' occurances of "' + key + '"')
112 for (var i = 0; i < values.length; i++) {
113 assert.strictEqual(headers[i], values[i])