-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.js
74 lines (62 loc) · 1.78 KB
/
response.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
const request = require('supertest');
const assert = require('assert');
const Koa = require('../..');
describe('app.response', () => {
const app1 = new Koa();
app1.response.msg = 'hello';
const app2 = new Koa();
const app3 = new Koa();
const app4 = new Koa();
const app5 = new Koa();
it('should merge properties', () => {
app1.use((ctx, next) => {
assert.equal(ctx.response.msg, 'hello');
ctx.status = 204;
});
return request(app1.listen())
.get('/')
.expect(204);
});
it('should not affect the original prototype', () => {
app2.use((ctx, next) => {
assert.equal(ctx.response.msg, undefined);
ctx.status = 204;
});
return request(app2.listen())
.get('/')
.expect(204);
});
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');
});
it('should set ._explicitNullBody correctly', async() => {
app4.use((ctx, next) => {
ctx.body = null;
assert.strictEqual(ctx.response._explicitNullBody, true);
});
return request(app4.listen())
.get('/')
.expect(204);
});
it('should not set ._explicitNullBody incorrectly', async() => {
app5.use((ctx, next) => {
ctx.body = undefined;
assert.strictEqual(ctx.response._explicitNullBody, undefined);
ctx.body = '';
assert.strictEqual(ctx.response._explicitNullBody, undefined);
ctx.body = false;
assert.strictEqual(ctx.response._explicitNullBody, undefined);
});
return request(app5.listen())
.get('/')
.expect(204);
});
});