Skip to content
Myr

res.json.js

This file

Path

test/res.json.js

177 lines · 4.5 KiB · JavaScript

Last changed by

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

History of this file

Take it

The walk stopped after 200 commits: lines older than 82731da point at it.

Merge pull request #1503 from shesek/settings-inheritanceTJ Holowaychukbefore adoption82731da

lines 1–30why, one step back
1
2var express = require('../')3 , request = require('./support/http')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 })1920 describe('when given primitives', function(){21 it('should respond with json', function(done){22 var app = express();2324 app.use(function(req, res){25 res.json(null);26 });2728 request(app)29 .get('/')30 .end(function(err, res){

Revert "remove charset from json responses. Closes #1631"TJ Holowaychukbefore adoption6cf6c8b

line 31why, one step back
31 res.headers.should.have.property('content-type', 'application/json; charset=utf-8');

Merge pull request #1503 from shesek/settings-inheritanceTJ Holowaychukbefore adoption82731da

lines 32–48why, one step back
32 res.text.should.equal('null');
33 done();34 })35 })36 })3738 describe('when given an array', function(){39 it('should respond with json', function(done){40 var app = express();4142 app.use(function(req, res){43 res.json(['foo', 'bar', 'baz']);44 });4546 request(app)47 .get('/')48 .end(function(err, res){

Revert "remove charset from json responses. Closes #1631"TJ Holowaychukbefore adoption6cf6c8b

line 49why, one step back
49 res.headers.should.have.property('content-type', 'application/json; charset=utf-8');

Merge pull request #1503 from shesek/settings-inheritanceTJ Holowaychukbefore adoption82731da

lines 50–54why, one step back
50 res.text.should.equal('["foo","bar","baz"]');
51 done();52 })53 })54 })

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

line 55why, one step back
55

Merge pull request #1503 from shesek/settings-inheritanceTJ Holowaychukbefore adoption82731da

lines 56–66why, one step back
56 describe('when given an object', function(){
57 it('should respond with json', function(done){58 var app = express();5960 app.use(function(req, res){61 res.json({ name: 'tobi' });62 });6364 request(app)65 .get('/')66 .end(function(err, res){

Revert "remove charset from json responses. Closes #1631"TJ Holowaychukbefore adoption6cf6c8b

line 67why, one step back
67 res.headers.should.have.property('content-type', 'application/json; charset=utf-8');

Merge pull request #1503 from shesek/settings-inheritanceTJ Holowaychukbefore adoption82731da

lines 68–97why, one step back
68 res.text.should.equal('{"name":"tobi"}');
69 done();70 })71 })72 })7374 describe('"json replacer" setting', function(){75 it('should be passed to JSON.stringify()', function(done){76 var app = express();7778 app.set('json replacer', function(key, val){79 return '_' == key[0]80 ? undefined81 : val;82 });8384 app.use(function(req, res){85 res.json({ name: 'tobi', _id: 12345 });86 });8788 request(app)89 .get('/')90 .end(function(err, res){91 res.text.should.equal('{"name":"tobi"}');92 done();93 });94 })95 })9697 describe('"json spaces" setting', function(){

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

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

Merge pull request #1503 from shesek/settings-inheritanceTJ Holowaychukbefore adoption82731da

lines 99–120why, one step back
99 var app = express();
100 assert(undefined === app.get('json spaces'));101 })102103 it('should be passed to JSON.stringify()', function(done){104 var app = express();105106 app.set('json spaces', 2);107108 app.use(function(req, res){109 res.json({ name: 'tobi', age: 2 });110 });111112 request(app)113 .get('/')114 .end(function(err, res){115 res.text.should.equal('{\n "name": "tobi",\n "age": 2\n}');116 done();117 });118 })119 })120 })

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

line 121why, one step back
121

Merge pull request #1503 from shesek/settings-inheritanceTJ Holowaychukbefore adoption82731da

lines 122–133why, one step back
122 describe('.json(status, object)', function(){
123 it('should respond with json and set the .statusCode', function(done){124 var app = express();125126 app.use(function(req, res){127 res.json(201, { id: 1 });128 });129130 request(app)131 .get('/')132 .end(function(err, res){133 res.statusCode.should.equal(201);

Revert "remove charset from json responses. Closes #1631"TJ Holowaychukbefore adoption6cf6c8b

line 134why, one step back
134 res.headers.should.have.property('content-type', 'application/json; charset=utf-8');

Merge pull request #1503 from shesek/settings-inheritanceTJ Holowaychukbefore adoption82731da

lines 135–152why, one step back
135 res.text.should.equal('{"id":1}');
136 done();137 })138 })139 })140141 describe('.json(object, status)', function(){142 it('should respond with json and set the .statusCode for backwards compat', function(done){143 var app = express();144145 app.use(function(req, res){146 res.json({ id: 1 }, 201);147 });148149 request(app)150 .get('/')151 .end(function(err, res){152 res.statusCode.should.equal(201);

Revert "remove charset from json responses. Closes #1631"TJ Holowaychukbefore adoption6cf6c8b

line 153why, one step back
153 res.headers.should.have.property('content-type', 'application/json; charset=utf-8');

Merge pull request #1503 from shesek/settings-inheritanceTJ Holowaychukbefore adoption82731da

lines 154–177why, one step back
154 res.text.should.equal('{"id":1}');
155 done();156 })157 })158 })159160 it('should not override previous Content-Types', function(done){161 var app = express();162163 app.get('/', function(req, res){164 res.type('application/vnd.example+json');165 res.json({ hello: 'world' });166 });167168 request(app)169 .get('/')170 .end(function(err, res){171 res.statusCode.should.equal(200);172 res.headers.should.have.property('content-type', 'application/vnd.example+json');173 res.text.should.equal('{"hello":"world"}');174 done();175 })176 })177})