2 var after = require('after')
3 var express = require('../')
4 , request = require('supertest');
6 describe('app', function(){
7 describe('.response', function(){
8 it('should extend the response prototype', function(done){
11 app.response.shout = function(str){
12 this.send(str.toUpperCase());
15 app.use(function(req, res){
24 it('should only extend for the referenced app', function (done) {
27 var cb = after(2, done)
29 app1.response.shout = function (str) {
30 this.send(str.toUpperCase())
33 app1.get('/', function (req, res) {
37 app2.get('/', function (req, res) {
43 .expect(200, 'FOO', cb)
47 .expect(500, /(?:not a function|has no method)/, cb)
50 it('should inherit to sub apps', function (done) {
53 var cb = after(2, done)
55 app1.response.shout = function (str) {
56 this.send(str.toUpperCase())
59 app1.use('/sub', app2)
61 app1.get('/', function (req, res) {
65 app2.get('/', function (req, res) {
71 .expect(200, 'FOO', cb)
75 .expect(200, 'FOO', cb)
78 it('should allow sub app to override', function (done) {
81 var cb = after(2, done)
83 app1.response.shout = function (str) {
84 this.send(str.toUpperCase())
87 app2.response.shout = function (str) {
91 app1.use('/sub', app2)
93 app1.get('/', function (req, res) {
97 app2.get('/', function (req, res) {
103 .expect(200, 'FOO', cb)
107 .expect(200, 'foo!', cb)
110 it('should not pollute parent app', function (done) {
113 var cb = after(2, done)
115 app1.response.shout = function (str) {
116 this.send(str.toUpperCase())
119 app2.response.shout = function (str) {
123 app1.use('/sub', app2)
125 app1.get('/sub/foo', function (req, res) {
129 app2.get('/', function (req, res) {
135 .expect(200, 'foo!', cb)
139 .expect(200, 'FOO', cb)