Skip to content

Commit

Permalink
deps: supertest@1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed May 18, 2015
1 parent 96b4a76 commit 7df8fa3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
12 changes: 10 additions & 2 deletions examples/params/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ var users = [
, { name: 'bandit' }
];

// Create HTTP error

function createError(status, message) {
var err = new Error(message);
err.status = status;
return err;
}

// Convert :to and :from to integers

app.param(['to', 'from'], function(req, res, next, num, name){
req.params[name] = parseInt(num, 10);
if( isNaN(req.params[name]) ){
next(new Error('failed to parseInt '+num));
next(createError(400, 'failed to parseInt '+num));
} else {
next();
}
Expand All @@ -33,7 +41,7 @@ app.param('user', function(req, res, next, id){
if (req.user = users[id]) {
next();
} else {
next(new Error('failed to find user'));
next(createError(404, 'failed to find user'));
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"marked": "0.3.3",
"mocha": "2.2.5",
"should": "~5.2.0",
"supertest": "~0.15.0"
"supertest": "1.0.1"
},
"engines": {
"node": ">= 0.8.0"
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/mvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('mvc', function(){
.put('/pet/3')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send({ pet: { name: 'Boots' } })
.end(function(err, res){
.expect(302, function (err, res) {
if (err) return done(err);
request(app)
.get('/pet/3/edit')
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('mvc', function(){
.put('/user/1')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send({ user: { name: 'Tobo' }})
.end(function(err, res){
.expect(302, function (err, res) {
if (err) return done(err);
request(app)
.get('/user/1/edit')
Expand Down
8 changes: 4 additions & 4 deletions test/acceptance/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe('params', function(){
describe('GET /user/9', function(){
it('should fail to find user', function(done){
request(app)
.get('/user/9')
.expect(/failed to find user/,done)
.get('/user/9')
.expect(404, /failed to find user/, done)
})
})

Expand All @@ -37,8 +37,8 @@ describe('params', function(){
describe('GET /users/foo-bar', function(){
it('should fail integer parsing', function(done){
request(app)
.get('/users/foo-bar')
.expect(/failed to parseInt foo/,done)
.get('/users/foo-bar')
.expect(400, /failed to parseInt foo/, done)
})
})
})

0 comments on commit 7df8fa3

Please sign in to comment.