3 var after
= require('after')
4 var express
= require('../')
5 , request
= require('supertest');
7 describe('app', function(){
8 describe('.response', function(){
9 it('should extend the response prototype', function(done
){
12 app
.response
.shout = function(str
){
13 this.send(str
.toUpperCase());
16 app
.use(function(req
, res
){
25 it('should only extend for the referenced app', function (done
) {
28 var cb
= after(2, done
)
30 app1
.response
.shout = function (str
) {
31 this.send(str
.toUpperCase())
34 app1
.get('/', function (req
, res
) {
38 app2
.get('/', function (req
, res
) {
44 .expect(200, 'FOO', cb
)
48 .expect(500, /(?:not a function|has no method)/, cb
)
51 it('should inherit to sub apps', function (done
) {
54 var cb
= after(2, done
)
56 app1
.response
.shout = function (str
) {
57 this.send(str
.toUpperCase())
60 app1
.use('/sub', app2
)
62 app1
.get('/', function (req
, res
) {
66 app2
.get('/', function (req
, res
) {
72 .expect(200, 'FOO', cb
)
76 .expect(200, 'FOO', cb
)
79 it('should allow sub app to override', function (done
) {
82 var cb
= after(2, done
)
84 app1
.response
.shout = function (str
) {
85 this.send(str
.toUpperCase())
88 app2
.response
.shout = function (str
) {
92 app1
.use('/sub', app2
)
94 app1
.get('/', function (req
, res
) {
98 app2
.get('/', function (req
, res
) {
104 .expect(200, 'FOO', cb
)
108 .expect(200, 'foo!', cb
)
111 it('should not pollute parent app', function (done
) {
114 var cb
= after(2, done
)
116 app1
.response
.shout = function (str
) {
117 this.send(str
.toUpperCase())
120 app2
.response
.shout = function (str
) {
124 app1
.use('/sub', app2
)
126 app1
.get('/sub/foo', function (req
, res
) {
130 app2
.get('/', function (req
, res
) {
136 .expect(200, 'foo!', cb
)
140 .expect(200, 'FOO', cb
)