res.set.js
This file
Path
test/res.set.js
80 lines · 2.0 KiB · JavaScript
Last changed by
Merge tag '3.9.0'Douglas Christopher Wilsonbefore adoptiondb4448d
History of this fileTake it
The walk stopped after 200 commits: lines older than 34c83d7 point at it.
3.4.7Jonathan Ongbefore adoption34c83d7
lines 1–2why, one step back12var express = require('../')remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 3why, one step back3 , request = require('supertest')3.4.7Jonathan Ongbefore adoption34c83d7
lines 4–11why, one step back4 , res = express.response;56describe('res', function(){7 describe('.set(field, value)', function(){8 it('should set the response header field', function(done){9 var app = express();1011 app.use(function(req, res){move setHeader charset patch to .setJonathan Ongbefore adoptionbad55f7
line 12why, one step back12 res.set('Content-Type', 'text/x-foo; charset=utf-8').end();3.4.7Jonathan Ongbefore adoption34c83d7
lines 13–16why, one step back13 });1415 request(app)16 .get('/')move setHeader charset patch to .setJonathan Ongbefore adoptionbad55f7
line 17why, one step back17 .expect('Content-Type', 'text/x-foo; charset=utf-8')3.4.7Jonathan Ongbefore adoption34c83d7
lines 18–22why, one step back18 .end(done);19 })2021 it('should coerce to a string', function(){22 res.headers = {};Merge tag '3.9.0'Douglas Christopher Wilsonbefore adoptiondb4448d
lines 23–24why, one step back23 res.set('X-Number', 123);24 res.get('X-Number').should.equal('123');3.4.7Jonathan Ongbefore adoption34c83d7
lines 25–43why, one step back25 })26 })2728 describe('.set(field, values)', function(){29 it('should set multiple response header fields', function(done){30 var app = express();3132 app.use(function(req, res){33 res.set('Set-Cookie', ["type=ninja", "language=javascript"]);34 res.send(res.get('Set-Cookie'));35 });3637 request(app)38 .get('/')39 .expect('["type=ninja","language=javascript"]', done);40 })4142 it('should coerce to an array of strings', function(){43 res.headers = {};Merge tag '3.9.0'Douglas Christopher Wilsonbefore adoptiondb4448d
lines 44–46why, one step back44 res.set('X-Numbers', [123, 456]);45 JSON.stringify(res.get('X-Numbers'))46 .should.equal('["123","456"]');move setHeader charset patch to .setJonathan Ongbefore adoptionbad55f7
lines 47–52why, one step back47 })4849 it('should not set a charset of one is already set', function () {50 res.headers = {};51 res.set('Content-Type', 'text/html; charset=lol');52 res.get('content-type').should.equal('text/html; charset=lol');3.4.7Jonathan Ongbefore adoption34c83d7
lines 53–54why, one step back53 })54 })remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 55why, one step back553.4.7Jonathan Ongbefore adoption34c83d7
lines 56–75why, one step back56 describe('.set(object)', function(){57 it('should set multiple fields', function(done){58 var app = express();5960 app.use(function(req, res){61 res.set({62 'X-Foo': 'bar',63 'X-Bar': 'baz'64 }).end();65 });6667 request(app)68 .get('/')69 .expect('X-Foo', 'bar')70 .expect('X-Bar', 'baz')71 .end(done);72 })7374 it('should coerce to a string', function(){75 res.headers = {};Merge tag '3.9.0'Douglas Christopher Wilsonbefore adoptiondb4448d
lines 76–77why, one step back76 res.set({ 'X-Number': 123 });77 res.get('X-Number').should.equal('123');3.4.7Jonathan Ongbefore adoption34c83d7
lines 78–80why, one step back78 })79 })80})