Skip to content
Myr

res.set.js

This file

Path

test/res.set.js

124 lines · 2.9 KiB · JavaScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 2027b87 point at it.

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 1–124why, one step back
1'use strict'
23var express = require('..');4var request = require('supertest');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 (done) {22 var app = express();2324 app.use(function (req, res) {25 res.set('X-Number', 123);26 res.end(typeof res.get('X-Number'));27 });2829 request(app)30 .get('/')31 .expect('X-Number', '123')32 .expect(200, 'string', done);33 })34 })3536 describe('.set(field, values)', function(){37 it('should set multiple response header fields', function(done){38 var app = express();3940 app.use(function(req, res){41 res.set('Set-Cookie', ["type=ninja", "language=javascript"]);42 res.send(res.get('Set-Cookie'));43 });4445 request(app)46 .get('/')47 .expect('["type=ninja","language=javascript"]', done);48 })4950 it('should coerce to an array of strings', function (done) {51 var app = express();5253 app.use(function (req, res) {54 res.set('X-Numbers', [123, 456]);55 res.end(JSON.stringify(res.get('X-Numbers')));56 });5758 request(app)59 .get('/')60 .expect('X-Numbers', '123, 456')61 .expect(200, '["123","456"]', done);62 })6364 it('should not set a charset of one is already set', function (done) {65 var app = express();6667 app.use(function (req, res) {68 res.set('Content-Type', 'text/html; charset=lol');69 res.end();70 });7172 request(app)73 .get('/')74 .expect('Content-Type', 'text/html; charset=lol')75 .expect(200, done);76 })7778 it('should throw when Content-Type is an array', function (done) {79 var app = express()8081 app.use(function (req, res) {82 res.set('Content-Type', ['text/html'])83 res.end()84 });8586 request(app)87 .get('/')88 .expect(500, /TypeError: Content-Type cannot be set to an Array/, done)89 })90 })9192 describe('.set(object)', function(){93 it('should set multiple fields', function(done){94 var app = express();9596 app.use(function(req, res){97 res.set({98 'X-Foo': 'bar',99 'X-Bar': 'baz'100 }).end();101 });102103 request(app)104 .get('/')105 .expect('X-Foo', 'bar')106 .expect('X-Bar', 'baz')107 .end(done);108 })109110 it('should coerce to a string', function (done) {111 var app = express();112113 app.use(function (req, res) {114 res.set({ 'X-Number': 123 });115 res.end(typeof res.get('X-Number'));116 });117118 request(app)119 .get('/')120 .expect('X-Number', '123')121 .expect(200, 'string', done);122 })123 })124})