tests: add more tests for app.request & app.response
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 141914e · Browse files · 2 files·+232 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+232 added−15 removed
- tests:+232 added−15 removed
Provenance
- Commit
00ad5be- Tree
45da601- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
141914e
2 files changed+232 added−15 removed
modified:test/app.request.js+119 added
12345612 unmodified lines192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
var after = require('after')var express = require('../') , request = require('supertest');
describe('app', function(){12 unmodified lines request(app) .get('/foo?name=tobi') .expect('name=tobi', done); })
it('should only extend for the referenced app', function (done) { var app1 = express() var app2 = express() var cb = after(2, done)
app1.request.foobar = function () { return 'tobi' }
app1.get('/', function (req, res) { res.send(req.foobar()) })
app2.get('/', function (req, res) { res.send(req.foobar()) })
request(app1) .get('/') .expect(200, 'tobi', cb)
request(app2) .get('/') .expect(500, /(?:not a function|has no method)/, cb) })
it('should inherit to sub apps', function (done) { var app1 = express() var app2 = express() var cb = after(2, done)
app1.request.foobar = function () { return 'tobi' }
app1.use('/sub', app2)
app1.get('/', function (req, res) { res.send(req.foobar()) })
app2.get('/', function (req, res) { res.send(req.foobar()) })
request(app1) .get('/') .expect(200, 'tobi', cb)
request(app1) .get('/sub') .expect(200, 'tobi', cb) })
it('should allow sub app to override', function (done) { var app1 = express() var app2 = express() var cb = after(2, done)
app1.request.foobar = function () { return 'tobi' }
app2.request.foobar = function () { return 'loki' }
app1.use('/sub', app2)
app1.get('/', function (req, res) { res.send(req.foobar()) })
app2.get('/', function (req, res) { res.send(req.foobar()) })
request(app1) .get('/') .expect(200, 'tobi', cb)
request(app1) .get('/sub') .expect(200, 'loki', cb) })
it('should not pollute parent app', function (done) { var app1 = express() var app2 = express() var cb = after(2, done)
app1.request.foobar = function () { return 'tobi' }
app2.request.foobar = function () { return 'loki' }
app1.use('/sub', app2)
app1.get('/sub/foo', function (req, res) { res.send(req.foobar()) })
app2.get('/', function (req, res) { res.send(req.foobar()) })
request(app1) .get('/sub') .expect(200, 'loki', cb)
request(app1) .get('/sub/foo') .expect(200, 'tobi', cb) }) })})modified:test/app.response.js+113 added-15 removed
12345613 unmodified lines2021222323242524252627282728292930313231323333343536353637373839403940414142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
var after = require('after')var express = require('../') , request = require('supertest');
describe('app', function(){13 unmodified lines .get('/') .expect('HEY', done); })
it('should not be influenced by other app protos', function(done){ var app = express() , app2 = express(); it('should only extend for the referenced app', function (done) { var app1 = express() var app2 = express() var cb = after(2, done)
app.response.shout = function(str){ this.send(str.toUpperCase()); }; app1.response.shout = function (str) { this.send(str.toUpperCase()) }
app2.response.shout = function(str){ this.send(str); }; app1.get('/', function (req, res) { res.shout('foo') })
app.use(function(req, res){ res.shout('hey'); }); app2.get('/', function (req, res) { res.shout('foo') })
request(app) .get('/') .expect('HEY', done); request(app1) .get('/') .expect(200, 'FOO', cb)
request(app2) .get('/') .expect(500, /(?:not a function|has no method)/, cb) })
it('should inherit to sub apps', function (done) { var app1 = express() var app2 = express() var cb = after(2, done)
app1.response.shout = function (str) { this.send(str.toUpperCase()) }
app1.use('/sub', app2)
app1.get('/', function (req, res) { res.shout('foo') })
app2.get('/', function (req, res) { res.shout('foo') })
request(app1) .get('/') .expect(200, 'FOO', cb)
request(app1) .get('/sub') .expect(200, 'FOO', cb) })
it('should allow sub app to override', function (done) { var app1 = express() var app2 = express() var cb = after(2, done)
app1.response.shout = function (str) { this.send(str.toUpperCase()) }
app2.response.shout = function (str) { this.send(str + '!') }
app1.use('/sub', app2)
app1.get('/', function (req, res) { res.shout('foo') })
app2.get('/', function (req, res) { res.shout('foo') })
request(app1) .get('/') .expect(200, 'FOO', cb)
request(app1) .get('/sub') .expect(200, 'foo!', cb) })
it('should not pollute parent app', function (done) { var app1 = express() var app2 = express() var cb = after(2, done)
app1.response.shout = function (str) { this.send(str.toUpperCase()) }
app2.response.shout = function (str) { this.send(str + '!') }
app1.use('/sub', app2)
app1.get('/sub/foo', function (req, res) { res.shout('foo') })
app2.get('/', function (req, res) { res.shout('foo') })
request(app1) .get('/sub') .expect(200, 'foo!', cb)
request(app1) .get('/sub/foo') .expect(200, 'FOO', cb) }) })})