req.param.js
This file
Path
test/req.param.js
60 lines · 1.2 KiB · JavaScript
Last changed by
Add express.json and express.urlencoded to parse bodiesDouglas Christopher Wilsonbefore adoptionc0136d8
History of this fileTake it
The walk stopped after 200 commits: lines older than 6210e47 point at it.
build: after@0.8.2Douglas Christopher Wilsonbefore adoption6210e47
lines 1–35why, one step back12var express = require('../')3 , request = require('supertest')45describe('req', function(){6 describe('.param(name, default)', function(){7 it('should use the default value unless defined', function(done){8 var app = express();910 app.use(function(req, res){11 res.end(req.param('name', 'tj'));12 });1314 request(app)15 .get('/')16 .expect('tj', done);17 })18 })1920 describe('.param(name)', function(){21 it('should check req.query', function(done){22 var app = express();2324 app.use(function(req, res){25 res.end(req.param('name'));26 });2728 request(app)29 .get('/?name=tj')30 .expect('tj', done);31 })3233 it('should check req.body', function(done){34 var app = express();35Add express.json and express.urlencoded to parse bodiesDouglas Christopher Wilsonbefore adoptionc0136d8
line 36why, one step back36 app.use(express.json())build: after@0.8.2Douglas Christopher Wilsonbefore adoption6210e47
lines 37–60why, one step back3738 app.use(function(req, res){39 res.end(req.param('name'));40 });4142 request(app)43 .post('/')44 .send({ name: 'tj' })45 .expect('tj', done);46 })4748 it('should check req.params', function(done){49 var app = express();5051 app.get('/user/:name', function(req, res){52 res.end(req.param('filter') + req.param('name'));53 });5455 request(app)56 .get('/user/tj')57 .expect('undefinedtj', done);58 })59 })60})