response.test.js
This file
Path
test/response.test.js
94 lines · 3.0 KiB · JavaScript
Last changed by
Added buffer support to res.send()Tj Holowaychukbefore adoption14280df
History of this fileTake it
Added response helpersTj Holowaychukbefore adoption874975d
lines 1–5why, one step back12/**3 * Module dependencies.4 */5Added buffer support to res.send()Tj Holowaychukbefore adoption14280df
lines 6–7why, one step back6var express = require('express'),7 Buffer = require('buffer').Buffer;Added response helpersTj Holowaychukbefore adoption874975d
lines 8–17why, one step back89module.exports = {10 '#send()': function(assert){11 var app = express.createServer();1213 app.get('/html', function(req, res){14 res.send('<p>test</p>', { 'Content-Language': 'en' });15 });16 17 app.get('/json', function(req, res){req.send() headers take precedenceTj Holowaychukbefore adoption0d4b57d
lines 18–19why, one step back18 res.header('X-Foo', 'bar');19 res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);Added response helpersTj Holowaychukbefore adoption874975d
line 20why, one step back20 });res.send() only setting Content-Type when not already presentTj Holowaychukbefore adoptionf0a0966
lines 21–22why, one step back21 22 app.get('/text', function(req, res){Added res.header()Tj Holowaychukbefore adoption838c470
line 23why, one step back23 res.header('X-Foo', 'bar');res.send() only setting Content-Type when not already presentTj Holowaychukbefore adoptionf0a0966
lines 24–26why, one step back24 res.contentType('.txt');25 res.send('wahoo');26 });Allowing status as first or second arg to res.send()Tj Holowaychukbefore adoption395d14a
lines 27–32why, one step back27 28 app.get('/status', function(req, res){29 res.send(404);30 });31 32 app.get('/error', function(req, res){Added res.send() Content-Type precedence testTj Holowaychukbefore adoptionc8baa8f
line 33why, one step back33 res.send('Oh shit!', { 'Content-Type': 'text/plain' }, 500);Allowing status as first or second arg to res.send()Tj Holowaychukbefore adoption395d14a
line 34why, one step back34 });Added buffer support to res.send()Tj Holowaychukbefore adoption14280df
lines 35–38why, one step back35 36 app.get('/buffer', function(req, res){37 res.send(new Buffer('wahoo!'));38 });Added response helpersTj Holowaychukbefore adoption874975d
lines 39–41why, one step back3940 assert.response(app,41 { url: '/html' },res.send() only setting Content-Type when not already presentTj Holowaychukbefore adoptionf0a0966
line 42why, one step back42 { body: '<p>test</p>', headers: { 'Content-Language': 'en', 'Content-Type': 'text/html; charset=utf-8' }});Added response helpersTj Holowaychukbefore adoption874975d
lines 43–44why, one step back43 assert.response(app,44 { url: '/json' },req.send() headers take precedenceTj Holowaychukbefore adoption0d4b57d
line 45why, one step back45 { body: '{"foo":"bar"}', status: 201, headers: { 'Content-Type': 'application/json', 'X-Foo': 'baz' }});res.send() only setting Content-Type when not already presentTj Holowaychukbefore adoptionf0a0966
lines 46–47why, one step back46 assert.response(app,47 { url: '/text' },Added res.header()Tj Holowaychukbefore adoption838c470
line 48why, one step back48 { body: 'wahoo', headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Foo': 'bar' }});Allowing status as first or second arg to res.send()Tj Holowaychukbefore adoption395d14a
lines 49–53why, one step back49 assert.response(app,50 { url: '/status' },51 { body: 'Not Found', status: 404, headers: { 'Content-Type': 'text/plain; charset=utf-8' }});52 assert.response(app,53 { url: '/error' },Added res.send() Content-Type precedence testTj Holowaychukbefore adoptionc8baa8f
line 54why, one step back54 { body: 'Oh shit!', status: 500, headers: { 'Content-Type': 'text/plain' }});Added buffer support to res.send()Tj Holowaychukbefore adoption14280df
lines 55–57why, one step back55 assert.response(app,56 { url: '/buffer' },57 { body: 'wahoo!' });Added res.contentType() testsTj Holowaychukbefore adoptionac17a6a
lines 58–71why, one step back58 },59 60 '#contentType': function(assert){61 var app = express.createServer();62 63 app.get('/html', function(req, res){64 res.contentType('index.html');65 res.writeHead(200, res.headers);66 res.end('<p>yay</p>');67 });68 69 assert.response(app,70 { url: '/html' },71 { body: '<p>yay</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});Added res.attachment()Tj Holowaychukbefore adoption8fdf111
lines 72–92why, one step back72 },73 74 '#attachment': function(assert){75 var app = express.createServer();76 77 app.get('/style.css', function(req, res){78 res.attachment();79 res.send('some stylezzz');80 });8182 app.get('/*', function(req, res, params){83 res.attachment(params.splat[0]);84 res.send('whatever');85 });86 87 assert.response(app,88 { url: '/javascripts/jquery.js' },89 { body: 'whatever', headers: { 'Content-Disposition': 'attachment; filename="jquery.js"' }});90 assert.response(app,91 { url: '/style.css' },92 { body: 'some stylezzz', headers: { 'Content-Disposition': 'attachment' }});Added response helpersTj Holowaychukbefore adoption874975d
lines 93–94why, one step back93 }94};