koa-lite/test/application/response.js

47 lines
1 KiB
JavaScript
Raw Normal View History

'use strict';
const request = require('supertest');
const assert = require('assert');
2015-10-13 06:19:42 +00:00
const Koa = require('../..');
describe('app.response', () => {
2015-10-13 06:19:42 +00:00
const app1 = new Koa();
app1.response.msg = 'hello';
2015-10-13 06:19:42 +00:00
const app2 = new Koa();
const app3 = new Koa();
2017-05-11 03:30:32 +00:00
it('should merge properties', () => {
app1.use((ctx, next) => {
assert.equal(ctx.response.msg, 'hello');
ctx.status = 204;
});
2017-05-11 03:30:32 +00:00
return request(app1.listen())
.get('/')
2017-05-11 03:30:32 +00:00
.expect(204);
2015-10-12 20:36:41 +00:00
});
2017-05-11 03:30:32 +00:00
it('should not affect the original prototype', () => {
app2.use((ctx, next) => {
assert.equal(ctx.response.msg, undefined);
ctx.status = 204;
});
2017-05-11 03:30:32 +00:00
return request(app2.listen())
.get('/')
2017-05-11 03:30:32 +00:00
.expect(204);
2015-10-12 20:36:41 +00:00
});
it('should not include status message in body for http2', async () => {
app3.use((ctx, next) => {
ctx.req.httpVersionMajor = 2;
ctx.status = 404;
});
const response = await request(app3.listen())
.get('/')
.expect(404);
assert.equal(response.text, '404');
});
2015-10-12 20:36:41 +00:00
});