res.set.js
This file
Path
test/res.set.js
110 lines · 2.6 KiB · JavaScript
Last changed by
Merge tag '3.19.1'Douglas Christopher Wilsonbefore adoption82689d6
History of this fileTake it
The walk stopped after 200 commits: lines older than 6bc7574 point at it.
docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
line 1why, one step back1Merge tag '3.19.1'Douglas Christopher Wilsonbefore adoption82689d6
lines 2–3why, one step back2var express = require('..');3var request = require('supertest');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 4–19why, one step back45describe('res', function(){6 describe('.set(field, value)', function(){7 it('should set the response header field', function(done){8 var app = express();910 app.use(function(req, res){11 res.set('Content-Type', 'text/x-foo; charset=utf-8').end();12 });1314 request(app)15 .get('/')16 .expect('Content-Type', 'text/x-foo; charset=utf-8')17 .end(done);18 })19Merge tag '3.19.1'Douglas Christopher Wilsonbefore adoption82689d6
lines 20–31why, one step back20 it('should coerce to a string', function (done) {21 var app = express();2223 app.use(function (req, res) {24 res.set('X-Number', 123);25 res.end(typeof res.get('X-Number'));26 });2728 request(app)29 .get('/')30 .expect('X-Number', '123')31 .expect(200, 'string', done);docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 32–48why, one step back32 })33 })3435 describe('.set(field, values)', function(){36 it('should set multiple response header fields', function(done){37 var app = express();3839 app.use(function(req, res){40 res.set('Set-Cookie', ["type=ninja", "language=javascript"]);41 res.send(res.get('Set-Cookie'));42 });4344 request(app)45 .get('/')46 .expect('["type=ninja","language=javascript"]', done);47 })48Merge tag '3.19.1'Douglas Christopher Wilsonbefore adoption82689d6
lines 49–60why, one step back49 it('should coerce to an array of strings', function (done) {50 var app = express();5152 app.use(function (req, res) {53 res.set('X-Numbers', [123, 456]);54 res.end(JSON.stringify(res.get('X-Numbers')));55 });5657 request(app)58 .get('/')59 .expect('X-Numbers', '123, 456')60 .expect(200, '["123","456"]', done);docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 61–62why, one step back61 })62Merge tag '3.19.1'Douglas Christopher Wilsonbefore adoption82689d6
lines 63–74why, one step back63 it('should not set a charset of one is already set', function (done) {64 var app = express();6566 app.use(function (req, res) {67 res.set('Content-Type', 'text/html; charset=lol');68 res.end();69 });7071 request(app)72 .get('/')73 .expect('Content-Type', 'text/html; charset=lol')74 .expect(200, done);docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 75–95why, one step back75 })76 })7778 describe('.set(object)', function(){79 it('should set multiple fields', function(done){80 var app = express();8182 app.use(function(req, res){83 res.set({84 'X-Foo': 'bar',85 'X-Bar': 'baz'86 }).end();87 });8889 request(app)90 .get('/')91 .expect('X-Foo', 'bar')92 .expect('X-Bar', 'baz')93 .end(done);94 })95Merge tag '3.19.1'Douglas Christopher Wilsonbefore adoption82689d6
lines 96–107why, one step back96 it('should coerce to a string', function (done) {97 var app = express();9899 app.use(function (req, res) {100 res.set({ 'X-Number': 123 });101 res.end(typeof res.get('X-Number'));102 });103104 request(app)105 .get('/')106 .expect('X-Number', '123')107 .expect(200, 'string', done);docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 108–110why, one step back108 })109 })110})