1 |
|
2 | var request = require('supertest');
|
3 | var json = require('..');
|
4 | var koa = require('koa');
|
5 |
|
6 | describe('pretty', function(){
|
7 | it('should default to true', function(done){
|
8 | var app = koa();
|
9 |
|
10 | app.use(json());
|
11 |
|
12 | app.use(function *(next){
|
13 | this.body = { foo: 'bar' };
|
14 | });
|
15 |
|
16 | request(app.listen())
|
17 | .get('/')
|
18 | .expect('{\n "foo": "bar"\n}', done);
|
19 | })
|
20 |
|
21 | it('should retain content-type', function(done){
|
22 | var app = koa();
|
23 |
|
24 | app.use(json());
|
25 |
|
26 | app.use(function *(next){
|
27 | this.body = { foo: 'bar' };
|
28 | });
|
29 |
|
30 | request(app.listen())
|
31 | .get('/')
|
32 | .expect('Content-Type', 'application/json', done);
|
33 | })
|
34 |
|
35 | it('should pass through when false', function(done){
|
36 | var app = koa();
|
37 |
|
38 | app.use(json({ pretty: false }));
|
39 |
|
40 | app.use(function *(next){
|
41 | this.body = { foo: 'bar' };
|
42 | });
|
43 |
|
44 | request(app.listen())
|
45 | .get('/')
|
46 | .expect('{"foo":"bar"}', done);
|
47 | })
|
48 | }) |
\ | No newline at end of file |