res.set.js
This file
Path
test/res.set.js
80 lines · 2.0 KiB · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 269dc53 point at it.
Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 1–80why, one step back12var express = require('../')3 , request = require('supertest')4 , 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){12 res.set('Content-Type', 'text/x-foo; charset=utf-8').end();13 });1415 request(app)16 .get('/')17 .expect('Content-Type', 'text/x-foo; charset=utf-8')18 .end(done);19 })2021 it('should coerce to a string', function(){22 res.headers = {};23 res.set('X-Number', 123);24 res.get('X-Number').should.equal('123');25 })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 = {};44 res.set('X-Numbers', [123, 456]);45 JSON.stringify(res.get('X-Numbers'))46 .should.equal('["123","456"]');47 })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');53 })54 })5556 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 = {};76 res.set({ 'X-Number': 123 });77 res.get('X-Number').should.equal('123');78 })79 })80})