app.param.js
This file
Path
test/app.param.js
99 lines · 2.3 KiB · JavaScript
Last changed by
updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e
History of this fileTake it
The walk stopped after 200 commits: lines older than 8f87400 point at it.
Fixed: use app.get() for all core settingsTJ Holowaychukbefore adoption8f87400
lines 1–31why, one step back12var express = require('../')3 , request = require('./support/http');45describe('app', function(){6 describe('.param(fn)', function(){7 it('should map app.param(name, ...) logic', function(done){8 var app = express();910 app.param(function(name, regexp){11 if (regexp instanceof RegExp) {12 return function(req, res, next, val){13 var captures;14 if (captures = regexp.exec(String(val))) {15 req.params[name] = captures[1];16 next();17 } else {18 next('route');19 }20 }21 }22 })2324 app.param(':name', /^([a-zA-Z]+)$/);2526 app.get('/user/:name', function(req, res){27 res.send(req.params.name);28 });2930 request(app)31 .get('/user/tj')updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e
lines 32–33why, one step back32 .end(function(err, res){33 res.text.should.equal('tj');Fixed: use app.get() for all core settingsTJ Holowaychukbefore adoption8f87400
lines 34–35why, one step back34 request(app)35 .get('/user/123')updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e
line 36why, one step back36 .expect(404, done);Fixed: use app.get() for all core settingsTJ Holowaychukbefore adoption8f87400
lines 37–66why, one step back37 });3839 })40 })4142 describe('.param(names, fn)', function(){43 it('should map the array', function(done){44 var app = express();4546 app.param(['id', 'uid'], function(req, res, next, id){47 id = Number(id);48 if (isNaN(id)) return next('route');49 req.params.id = id;50 next();51 });5253 app.get('/post/:id', function(req, res){54 var id = req.params.id;55 id.should.be.a('number');56 res.send('' + id);57 });5859 app.get('/user/:uid', function(req, res){60 var id = req.params.id;61 id.should.be.a('number');62 res.send('' + id);63 });6465 request(app)66 .get('/user/123')updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e
lines 67–68why, one step back67 .end(function(err, res){68 res.text.should.equal('123');Fixed: use app.get() for all core settingsTJ Holowaychukbefore adoption8f87400
lines 69–71why, one step back6970 request(app)71 .get('/post/123')updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e
line 72why, one step back72 .expect('123', done);Fixed: use app.get() for all core settingsTJ Holowaychukbefore adoption8f87400
lines 73–95why, one step back73 })74 })75 })7677 describe('.param(name, fn)', function(){78 it('should map logic for a single param', function(done){79 var app = express();8081 app.param('id', function(req, res, next, id){82 id = Number(id);83 if (isNaN(id)) return next('route');84 req.params.id = id;85 next();86 });8788 app.get('/user/:id', function(req, res){89 var id = req.params.id;90 id.should.be.a('number');91 res.send('' + id);92 });9394 request(app)95 .get('/user/123')updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e
line 96why, one step back96 .expect('123', done);Fixed: use app.get() for all core settingsTJ Holowaychukbefore adoption8f87400
lines 97–99why, one step back97 })98 })99})