Skip to content

Commit

Permalink
tests: ensure all errors are handled
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jun 20, 2016
1 parent 74d5ab5 commit 1050e7b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/body-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ describe('bodyParser()', function(){
.expect(200, '{"user":"tobi"}', done)
})

it('should handle duplicated middleware', function(done){
it('should handle duplicated middleware', function (done) {
var _bodyParser = bodyParser()
var server = http.createServer(function(req, res){
_bodyParser(req, res, function(err){
_bodyParser(req, res, function(err){
res.statusCode = err ? (err.status || 500) : 200;
res.end(err ? err.message : JSON.stringify(req.body));
var server = http.createServer(function (req, res) {
_bodyParser(req, res, function (err0) {
_bodyParser(req, res, function (err1) {
var err = err0 || err1
res.statusCode = err ? (err.status || 500) : 200
res.end(err ? err.message : JSON.stringify(req.body))
})
})
})
Expand Down
1 change: 1 addition & 0 deletions test/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe('bodyParser.json()', function(){
var jsonParser = bodyParser.json()
var server = createServer(function (req, res, next) {
jsonParser(req, res, function (err) {
if (err) return next(err)
jsonParser(req, res, next)
})
})
Expand Down
1 change: 1 addition & 0 deletions test/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('bodyParser.raw()', function(){
var rawParser = bodyParser.raw()
var server = createServer(function (req, res, next) {
rawParser(req, res, function (err) {
if (err) return next(err)
rawParser(req, res, next)
})
})
Expand Down
1 change: 1 addition & 0 deletions test/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('bodyParser.text()', function(){
var textParser = bodyParser.text()
var server = createServer(function (req, res, next) {
textParser(req, res, function (err) {
if (err) return next(err)
textParser(req, res, next)
})
})
Expand Down
1 change: 1 addition & 0 deletions test/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('bodyParser.urlencoded()', function(){
var urlencodedParser = bodyParser.urlencoded()
var server = createServer(function (req, res, next) {
urlencodedParser(req, res, function (err) {
if (err) return next(err)
urlencodedParser(req, res, next)
})
})
Expand Down

0 comments on commit 1050e7b

Please sign in to comment.