Skip to content
Myr

res.json.js

This file

Path

test/res.json.js

191 lines · 4.8 KiB · JavaScript

Last changed by

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

History of this file

Take it

The walk stopped after 200 commits: lines older than 2e68ddb point at it.

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 1–2why, one step back
1
2var express = require('../')

remove unnecessary test/support/httpJonathan Ongbefore adoption643397e

line 3why, one step back
3 , request = require('supertest')

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 4–19why, one step back
4 , assert = require('assert');
56describe('res', function(){7 describe('.json(object)', function(){8 it('should not support jsonp callbacks', function(done){9 var app = express();1011 app.use(function(req, res){12 res.json({ foo: 'bar' });13 });1415 request(app)16 .get('/?callback=foo')17 .expect('{"foo":"bar"}', done);18 })19

tests: fixup new json testsDouglas Christopher Wilsonbefore adoptione4302b2

lines 20–29why, one step back
20 it('should not override previous Content-Types', function(done){
21 var app = express();2223 app.get('/', function(req, res){24 res.type('application/vnd.example+json');25 res.json({ hello: 'world' });26 });2728 request(app)29 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

line 30why, one step back
30 .expect('Content-Type', 'application/vnd.example+json; charset=utf-8')

tests: fixup new json testsDouglas Christopher Wilsonbefore adoptione4302b2

lines 31–33why, one step back
31 .expect(200, '{"hello":"world"}', done);
32 })33

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

line 34why, one step back
34 describe('when given primitives', function(){

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

line 35why, one step back
35 it('should respond with json for null', function(done){

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 36–43why, one step back
36 var app = express();
3738 app.use(function(req, res){39 res.json(null);40 });4142 request(app)43 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 44–45why, one step back
44 .expect('Content-Type', 'application/json; charset=utf-8')
45 .expect(200, 'null', done)

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

line 46why, one step back
46 })

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

lines 47–56why, one step back
47
48 it('should respond with json for Number', function(done){49 var app = express();5051 app.use(function(req, res){52 res.json(300);53 });5455 request(app)56 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 57–58why, one step back
57 .expect('Content-Type', 'application/json; charset=utf-8')
58 .expect(200, '300', done)

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

lines 59–69why, one step back
59 })
6061 it('should respond with json for String', function(done){62 var app = express();6364 app.use(function(req, res){65 res.json('str');66 });6768 request(app)69 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 70–71why, one step back
70 .expect('Content-Type', 'application/json; charset=utf-8')
71 .expect(200, '"str"', done)

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

line 72why, one step back
72 })

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 73–84why, one step back
73 })
7475 describe('when given an array', function(){76 it('should respond with json', function(done){77 var app = express();7879 app.use(function(req, res){80 res.json(['foo', 'bar', 'baz']);81 });8283 request(app)84 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 85–86why, one step back
85 .expect('Content-Type', 'application/json; charset=utf-8')
86 .expect(200, '["foo","bar","baz"]', done)

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 87–88why, one step back
87 })
88 })

Merge pull request #1899 from visionmedia/remove-configureRoman Shtylmanbefore adoptionac2cbef

line 89why, one step back
89

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 90–99why, one step back
90 describe('when given an object', function(){
91 it('should respond with json', function(done){92 var app = express();9394 app.use(function(req, res){95 res.json({ name: 'tobi' });96 });9798 request(app)99 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 100–101why, one step back
100 .expect('Content-Type', 'application/json; charset=utf-8')
101 .expect(200, '{"name":"tobi"}', done)

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 102–120why, one step back
102 })
103 })104105 describe('"json replacer" setting', function(){106 it('should be passed to JSON.stringify()', function(done){107 var app = express();108109 app.set('json replacer', function(key, val){110 return '_' == key[0]111 ? undefined112 : val;113 });114115 app.use(function(req, res){116 res.json({ name: 'tobi', _id: 12345 });117 });118119 request(app)120 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 121–122why, one step back
121 .expect('Content-Type', 'application/json; charset=utf-8')
122 .expect(200, '{"name":"tobi"}', done)

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 123–126why, one step back
123 })
124 })125126 describe('"json spaces" setting', function(){

Merge pull request #1899 from visionmedia/remove-configureRoman Shtylmanbefore adoptionac2cbef

line 127why, one step back
127 it('should be undefined by default', function(){

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 128–142why, one step back
128 var app = express();
129 assert(undefined === app.get('json spaces'));130 })131132 it('should be passed to JSON.stringify()', function(done){133 var app = express();134135 app.set('json spaces', 2);136137 app.use(function(req, res){138 res.json({ name: 'tobi', age: 2 });139 });140141 request(app)142 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 143–144why, one step back
143 .expect('Content-Type', 'application/json; charset=utf-8')
144 .expect(200, '{\n "name": "tobi",\n "age": 2\n}', done)

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 145–147why, one step back
145 })
146 })147 })

Merge pull request #1899 from visionmedia/remove-configureRoman Shtylmanbefore adoptionac2cbef

line 148why, one step back
148

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 149–158why, one step back
149 describe('.json(status, object)', function(){
150 it('should respond with json and set the .statusCode', function(done){151 var app = express();152153 app.use(function(req, res){154 res.json(201, { id: 1 });155 });156157 request(app)158 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 159–160why, one step back
159 .expect('Content-Type', 'application/json; charset=utf-8')
160 .expect(201, '{"id":1}', done)

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 161–173why, one step back
161 })
162 })163164 describe('.json(object, status)', function(){165 it('should respond with json and set the .statusCode for backwards compat', function(done){166 var app = express();167168 app.use(function(req, res){169 res.json({ id: 1 }, 201);170 });171172 request(app)173 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 174–175why, one step back
174 .expect('Content-Type', 'application/json; charset=utf-8')
175 .expect(201, '{"id":1}', done)

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

lines 176–186why, one step back
176 })
177178 it('should use status as second number for backwards compat', function(done){179 var app = express();180181 app.use(function(req, res){182 res.json(200, 201);183 });184185 request(app)186 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 187–188why, one step back
187 .expect('Content-Type', 'application/json; charset=utf-8')
188 .expect(201, '200', done)

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 189–191why, one step back
189 })
190 })191})