request.test.js
This file
Path
test/request.test.js
109 lines · 3.5 KiB · JavaScript
Last changed by
Finished req.accepts()Tj Holowaychukbefore adoptione58f468
History of this fileTake it
Added req.isXMLHttpRequestTj Holowaychukbefore adoption1fe7bb2
lines 1–5why, one step back12/**3 * Module dependencies.4 */5Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 6–7why, one step back6var express = require('express'),7 connect = require('connect');Added req.isXMLHttpRequestTj Holowaychukbefore adoption1fe7bb2
lines 8–13why, one step back89module.exports = {10 '#isXMLHttpRequest': function(assert){11 var app = express.createServer();12 13 app.get('/isxhr', function(req, res, params){Added req.xhr as alias of req.isXMLHttpRequestTj Holowaychukbefore adoption35af1ba
line 14why, one step back14 assert.equal(req.xhr, req.isXMLHttpRequest);Added req.isXMLHttpRequestTj Holowaychukbefore adoption1fe7bb2
lines 15–26why, one step back15 res.send(req.isXMLHttpRequest16 ? 'yeaaa boy'17 : 'nope');18 });19 20 assert.response(app,21 { url: '/isxhr' },22 { body: 'nope' });23 24 assert.response(app,25 { url: '/isxhr', headers: { 'X-Requested-With': 'XMLHttpRequest' } },26 { body: 'yeaaa boy' });Added req.header() testsTj Holowaychukbefore adoption7897460
lines 27–40why, one step back27 },28 29 '#header()': function(assert){30 var app = express.createServer();31 32 app.get('/', function(req, res){33 assert.equal('foo.com', req.header('Host'));34 assert.equal('foo.com', req.header('host'));35 res.send('wahoo');36 });37 38 assert.response(app,39 { url: '/', headers: { Host: 'foo.com' }},40 { body: 'wahoo' });Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 41–42why, one step back41 },42 Added req.accepts()Tj Holowaychukbefore adoptioncf37966
lines 43–62why, one step back43 '#accepts()': function(assert){44 var app = express.createServer();45 46 app.get('/all', function(req, res){47 assert.strictEqual(true, req.accepts('html'));48 assert.strictEqual(true, req.accepts('json'));49 res.send('ok');50 });51 52 app.get('/', function(req, res){53 assert.strictEqual(true, req.accepts('html'));54 assert.strictEqual(true, req.accepts('text/html'));55 assert.strictEqual(true, req.accepts('text/*'));56 assert.strictEqual(true, req.accepts('json'));57 assert.strictEqual(true, req.accepts('application/json'));58 assert.strictEqual(false, req.accepts('xml'));59 assert.strictEqual(false, req.accepts());60 res.send('ok');61 });62 Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 63–67why, one step back63 app.get('/type', function(req, res){64 assert.strictEqual(true, req.accepts('html'));65 assert.strictEqual(true, req.accepts('text/html'));66 assert.strictEqual(true, req.accepts('json'));67 assert.strictEqual(true, req.accepts('application/json'));Finished req.accepts()Tj Holowaychukbefore adoptione58f468
lines 68–69why, one step back68 assert.strictEqual(false, req.accepts('png'));69 assert.strictEqual(false, req.accepts('image/png'));Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 70–72why, one step back70 res.send('ok'); 71 });72 Added req.accepts()Tj Holowaychukbefore adoptioncf37966
lines 73–74why, one step back73 assert.response(app,74 { url: '/all', headers: { Accept: '*/*' }},Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 75–77why, one step back75 { body: 'ok' });76 assert.response(app,77 { url: '/type', headers: { Accept: 'text/*; application/*' }},Added req.accepts()Tj Holowaychukbefore adoptioncf37966
lines 78–83why, one step back78 { body: 'ok' });79 assert.response(app,80 { url: '/', headers: { Accept: 'text/html; application/json; text/*' }},81 { body: 'ok' });82 },83 Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 84–107why, one step back84 '#param()': function(assert){85 var app = express.createServer(86 connect.bodyDecoder()87 );88 89 app.get('/user/:id?', function(req, res){90 res.send('user ' + req.param('id'));91 });92 93 app.post('/user', function(req, res){94 res.send('user ' + req.param('id'));95 });96 97 assert.response(app,98 { url: '/user/12' },99 { body: 'user 12' });100 101 assert.response(app,102 { url: '/user?id=5' },103 { body: 'user 5' });104 105 assert.response(app,106 { url: '/user', method: 'POST', data: 'id=1', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},107 { body: 'user 1' });Added req.isXMLHttpRequestTj Holowaychukbefore adoption1fe7bb2
lines 108–109why, one step back108 }109};