docs: update homepage link http to https (#5920)
[express.git] / test / app.response.js
blob5fb69f6275a8cd5f763ab811318ce4e78b84cdc9
1 'use strict'
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){
10 var app = express();
12 app.response.shout = function(str){
13 this.send(str.toUpperCase());
16 app.use(function(req, res){
17 res.shout('hey');
18 });
20 request(app)
21 .get('/')
22 .expect('HEY', done);
25 it('should only extend for the referenced app', function (done) {
26 var app1 = express()
27 var app2 = express()
28 var cb = after(2, done)
30 app1.response.shout = function (str) {
31 this.send(str.toUpperCase())
34 app1.get('/', function (req, res) {
35 res.shout('foo')
38 app2.get('/', function (req, res) {
39 res.shout('foo')
42 request(app1)
43 .get('/')
44 .expect(200, 'FOO', cb)
46 request(app2)
47 .get('/')
48 .expect(500, /(?:not a function|has no method)/, cb)
51 it('should inherit to sub apps', function (done) {
52 var app1 = express()
53 var app2 = express()
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) {
63 res.shout('foo')
66 app2.get('/', function (req, res) {
67 res.shout('foo')
70 request(app1)
71 .get('/')
72 .expect(200, 'FOO', cb)
74 request(app1)
75 .get('/sub')
76 .expect(200, 'FOO', cb)
79 it('should allow sub app to override', function (done) {
80 var app1 = express()
81 var app2 = express()
82 var cb = after(2, done)
84 app1.response.shout = function (str) {
85 this.send(str.toUpperCase())
88 app2.response.shout = function (str) {
89 this.send(str + '!')
92 app1.use('/sub', app2)
94 app1.get('/', function (req, res) {
95 res.shout('foo')
98 app2.get('/', function (req, res) {
99 res.shout('foo')
102 request(app1)
103 .get('/')
104 .expect(200, 'FOO', cb)
106 request(app1)
107 .get('/sub')
108 .expect(200, 'foo!', cb)
111 it('should not pollute parent app', function (done) {
112 var app1 = express()
113 var app2 = express()
114 var cb = after(2, done)
116 app1.response.shout = function (str) {
117 this.send(str.toUpperCase())
120 app2.response.shout = function (str) {
121 this.send(str + '!')
124 app1.use('/sub', app2)
126 app1.get('/sub/foo', function (req, res) {
127 res.shout('foo')
130 app2.get('/', function (req, res) {
131 res.shout('foo')
134 request(app1)
135 .get('/sub')
136 .expect(200, 'foo!', cb)
138 request(app1)
139 .get('/sub/foo')
140 .expect(200, 'FOO', cb)