fixed some tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent bcfcce3 · Browse files · 2 files·+16 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+16 added−17 removed
- tests:+12 added−13 removed
- other:+4 added−4 removed
Provenance
- Commit
d853f6c- Tree
f0748e9- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
bcfcce3
2 files changed+16 added−17 removed
modified:lib/response.js+4 added-4 removed
61 unmodified lines62 if (!this.header('Content-Type')) {63 this.contentType('.bin');64 }65 } else {66- return this.json(body, headers, status);66+ return this.json(body, status);67 }68 break;69 }70 26 unmodified lines97 * res.json('oh noes!', 500);98 * res.json('I dont have that', 404);99 *100 * @param {Mixed} obj101- * @param {Object|Number} headers or status101 * @param {Number} status102+ * @param {Number} status103 * @return {ServerResponse}104 * @api public105 */106 107-res.json = function(obj, headers, status){107+res.json = function(obj, status){108 var body = JSON.stringify(obj)109 , callback = this.req.query.callback110 , jsonp = this.app.enabled('jsonp callback');111 4 unmodified lines116 this.header('Content-Type', 'text/javascript');117 body = callback.replace(/[^\w$.]/g, '') + '(' + body + ');';118 }119 120- return this.send(body, headers, status);120+ return this.send(body, status);121 };122 123 /**124 * Set status `code`.280 unmodified linesmodified:test/response.test.js+12 added-13 removed
58 unmodified lines59 'test #send()': function(){60 var app = express.createServer();61 62 app.get('/html', function(req, res){63- res.send('<p>test</p>', { 'Content-Language': 'en' });63+ res.send('<p>test</p>');64 });65 66 app.get('/json', function(req, res){67 res.header('X-Foo', 'bar');68- res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);68+ res.send({ foo: 'bar' }, 201);69 });70 71 app.get('/text', function(req, res){72 res.header('X-Foo', 'bar');9 unmodified lines82 res.send('Oh noes!', 404);83 });84 85 app.get('/error', function(req, res){86- res.send('Oh shit!', { 'Content-Type': 'text/plain' }, 500);86+ res.send('Oh shit!', 500);87 });88 89 app.get('/buffer', function(req, res){90 res.send(new Buffer('wahoo!'));19 unmodified lines110 assert.response(app,111 { url: '/html' },112 { body: '<p>test</p>'113 , headers: {114- 'Content-Language': 'en'115- , 'Content-Type': 'text/html; charset=utf-8'114+ 'Content-Type': 'text/html; charset=utf-8'115 }});116 117 assert.response(app,118 { url: '/json' },66 unmodified lines185 app.enable('jsonp callback');186 187 app.get('/jsonp', function(req, res){188 res.header('X-Foo', 'bar');190- res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);189+ res.send({ foo: 'bar' }, 201);190 });191 192 assert.response(app,193 { url: '/jsonp?callback=test' },194 { body: 'test({"foo":"bar"});'195 , status: 201196 , headers: {197 'Content-Type': 'text/javascript; charset=utf-8'199- , 'X-Foo': 'baz'198+ , 'X-Foo': 'bar'199 }});200 201 assert.response(app,202 { url: '/jsonp?callback=baz' },203 { body: 'baz({"foo":"bar"});'204 , status: 201, headers: {205 'Content-Type': 'text/javascript; charset=utf-8'207- , 'X-Foo': 'baz'206+ , 'X-Foo': 'bar'207 }});208 209 assert.response(app,210 { url: '/jsonp?callback=invalid()[]' },211 { body: 'invalid({"foo":"bar"});'212 , status: 201213 , headers: {214 'Content-Type': 'text/javascript; charset=utf-8'216- , 'X-Foo': 'baz'215+ , 'X-Foo': 'bar'216 }});217 },218 219 'test #json() JSONP': function(){2 unmodified lines222 app.enable('jsonp callback');223 224 app.get('/jsonp', function(req, res){225 res.header('X-Foo', 'bar');227- res.json({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);226+ res.json({ foo: 'bar' }, 201);227 });228 229 assert.response(app,230 { url: '/jsonp?callback=test' },231 { body: 'test({"foo":"bar"});'232 , status: 201233 , headers: {234 'Content-Type': 'text/javascript; charset=utf-8'236- , 'X-Foo': 'baz'235+ , 'X-Foo': 'bar'236 }});237 238 assert.response(app,239 { url: '/jsonp?callback=baz' },240 { body: 'baz({"foo":"bar"});'241 , status: 201, headers: {242 'Content-Type': 'text/javascript; charset=utf-8'244- , 'X-Foo': 'baz'243+ , 'X-Foo': 'bar'244 }});245 246 assert.response(app,247 { url: '/jsonp?callback=invalid()[]' },248 { body: 'invalid({"foo":"bar"});'249 , status: 201250 , headers: {251 'Content-Type': 'text/javascript; charset=utf-8'253- , 'X-Foo': 'baz'252+ , 'X-Foo': 'bar'253 }});254 },255 256 'test #contentType()': function(){509 unmodified lines