2015-10-12 04:59:30 +00:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const request = require('supertest');
|
|
|
|
const assert = require('assert');
|
2015-10-13 06:19:42 +00:00
|
|
|
const Koa = require('../..');
|
2015-10-12 04:59:30 +00:00
|
|
|
|
|
|
|
describe('app.request', function(){
|
2015-10-13 06:19:42 +00:00
|
|
|
const app1 = new Koa();
|
2015-10-12 04:59:30 +00:00
|
|
|
app1.request.message = 'hello';
|
2015-10-13 06:19:42 +00:00
|
|
|
const app2 = new Koa();
|
2015-10-12 04:59:30 +00:00
|
|
|
|
|
|
|
it('should merge properties', function(done){
|
2015-10-27 14:59:40 +00:00
|
|
|
app1.use(function(ctx, next){
|
2015-10-14 00:45:18 +00:00
|
|
|
assert.equal(ctx.request.message, 'hello');
|
|
|
|
ctx.status = 204;
|
2015-10-12 04:59:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
request(app1.listen())
|
2015-10-28 07:53:49 +00:00
|
|
|
.get('/')
|
|
|
|
.expect(204, done);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
2015-10-12 04:59:30 +00:00
|
|
|
|
|
|
|
it('should not affect the original prototype', function(done){
|
2015-10-27 14:59:40 +00:00
|
|
|
app2.use(function(ctx, next){
|
2015-10-14 00:45:18 +00:00
|
|
|
assert.equal(ctx.request.message, undefined);
|
|
|
|
ctx.status = 204;
|
2015-10-12 04:59:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
request(app2.listen())
|
2015-10-28 07:53:49 +00:00
|
|
|
.get('/')
|
|
|
|
.expect(204, done);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|