Skip to content
Myr

app.response.js

This file

Path

test/app.response.js

143 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–143why, one step back
1'use strict'
23var after = require('after')4var express = require('../')5 , request = require('supertest');67describe('app', function(){8 describe('.response', function(){9 it('should extend the response prototype', function(done){10 var app = express();1112 app.response.shout = function(str){13 this.send(str.toUpperCase());14 };1516 app.use(function(req, res){17 res.shout('hey');18 });1920 request(app)21 .get('/')22 .expect('HEY', done);23 })2425 it('should only extend for the referenced app', function (done) {26 var app1 = express()27 var app2 = express()28 var cb = after(2, done)2930 app1.response.shout = function (str) {31 this.send(str.toUpperCase())32 }3334 app1.get('/', function (req, res) {35 res.shout('foo')36 })3738 app2.get('/', function (req, res) {39 res.shout('foo')40 })4142 request(app1)43 .get('/')44 .expect(200, 'FOO', cb)4546 request(app2)47 .get('/')48 .expect(500, /(?:not a function|has no method)/, cb)49 })5051 it('should inherit to sub apps', function (done) {52 var app1 = express()53 var app2 = express()54 var cb = after(2, done)5556 app1.response.shout = function (str) {57 this.send(str.toUpperCase())58 }5960 app1.use('/sub', app2)6162 app1.get('/', function (req, res) {63 res.shout('foo')64 })6566 app2.get('/', function (req, res) {67 res.shout('foo')68 })6970 request(app1)71 .get('/')72 .expect(200, 'FOO', cb)7374 request(app1)75 .get('/sub')76 .expect(200, 'FOO', cb)77 })7879 it('should allow sub app to override', function (done) {80 var app1 = express()81 var app2 = express()82 var cb = after(2, done)8384 app1.response.shout = function (str) {85 this.send(str.toUpperCase())86 }8788 app2.response.shout = function (str) {89 this.send(str + '!')90 }9192 app1.use('/sub', app2)9394 app1.get('/', function (req, res) {95 res.shout('foo')96 })9798 app2.get('/', function (req, res) {99 res.shout('foo')100 })101102 request(app1)103 .get('/')104 .expect(200, 'FOO', cb)105106 request(app1)107 .get('/sub')108 .expect(200, 'foo!', cb)109 })110111 it('should not pollute parent app', function (done) {112 var app1 = express()113 var app2 = express()114 var cb = after(2, done)115116 app1.response.shout = function (str) {117 this.send(str.toUpperCase())118 }119120 app2.response.shout = function (str) {121 this.send(str + '!')122 }123124 app1.use('/sub', app2)125126 app1.get('/sub/foo', function (req, res) {127 res.shout('foo')128 })129130 app2.get('/', function (req, res) {131 res.shout('foo')132 })133134 request(app1)135 .get('/sub')136 .expect(200, 'foo!', cb)137138 request(app1)139 .get('/sub/foo')140 .expect(200, 'FOO', cb)141 })142 })143})