add tests for exposing app-specific prototypes
This commit is contained in:
parent
0be1442111
commit
e6cd31ce2f
1 changed files with 84 additions and 0 deletions
|
@ -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);
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue