add tests for exposing app-specific prototypes

This commit is contained in:
Jonathan Ong 2013-11-13 18:41:01 -08:00
parent 0be1442111
commit e6cd31ce2f

View file

@ -295,3 +295,87 @@ describe('app.respond', function(){
}) })
}) })
}) })
describe('app.context', function(){
var app1 = koa();
app1.context.message = 'hello';
var app2 = koa();
it('should merge properties', function(){
app1.use(function *(next){
assert.equal(this.message, 'hello')
this.status = 204
});
request(app1.listen())
.get('/')
.expect(204);
})
it('should not affect the original prototype', function(){
app2.use(function *(next){
assert.equal(this.message, undefined)
this.status = 204;
});
request(app2.listen())
.get('/')
.expect(204);
})
})
describe('app.request', function(){
var app1 = koa();
app1.request.message = 'hello';
var app2 = koa();
it('should merge properties', function(){
app1.use(function *(next){
assert.equal(this.request.message, 'hello')
this.status = 204
});
request(app1.listen())
.get('/')
.expect(204);
})
it('should not affect the original prototype', function(){
app2.use(function *(next){
assert.equal(this.request.message, undefined)
this.status = 204;
});
request(app2.listen())
.get('/')
.expect(204);
})
})
describe('app.response', function(){
var app1 = koa();
app1.response.message = 'hello';
var app2 = koa();
it('should merge properties', function(){
app1.use(function *(next){
assert.equal(this.response.message, 'hello')
this.status = 204
});
request(app1.listen())
.get('/')
.expect(204);
})
it('should not affect the original prototype', function(){
app2.use(function *(next){
assert.equal(this.response.message, undefined)
this.status = 204;
});
request(app2.listen())
.get('/')
.expect(204);
})
})