Skip to content

Commit 141914e

Browse files
committed
tests: fix tests that did not bubble errors
1 parent bd4fdfe commit 141914e

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

test/app.all.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11

2+
var after = require('after')
23
var express = require('../')
34
, request = require('supertest');
45

56
describe('app.all()', function(){
67
it('should add a router per method', function(done){
78
var app = express();
9+
var cb = after(2, done)
810

911
app.all('/tobi', function(req, res){
1012
res.end(req.method);
1113
});
1214

1315
request(app)
14-
.put('/tobi')
15-
.expect('PUT', function(){
16-
request(app)
16+
.put('/tobi')
17+
.expect(200, 'PUT', cb)
18+
19+
request(app)
1720
.get('/tobi')
18-
.expect('GET', done);
19-
});
21+
.expect(200, 'GET', cb)
2022
})
2123

2224
it('should run the callback for a method just once', function(done){

test/app.head.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,20 @@ describe('HEAD', function(){
4646
describe('app.head()', function(){
4747
it('should override', function(done){
4848
var app = express()
49-
, called;
5049

5150
app.head('/tobi', function(req, res){
52-
called = true;
53-
res.end('');
51+
res.header('x-method', 'head')
52+
res.end()
5453
});
5554

5655
app.get('/tobi', function(req, res){
57-
assert(0, 'should not call GET');
56+
res.header('x-method', 'get')
5857
res.send('tobi');
5958
});
6059

6160
request(app)
62-
.head('/tobi')
63-
.expect(200, function(){
64-
assert(called);
65-
done();
66-
});
61+
.head('/tobi')
62+
.expect('x-method', 'head')
63+
.expect(200, done)
6764
})
6865
})

test/app.router.js

+18-15
Original file line numberDiff line numberDiff line change
@@ -636,18 +636,19 @@ describe('app.router', function(){
636636

637637
it('should work cross-segment', function(done){
638638
var app = express();
639+
var cb = after(2, done)
639640

640641
app.get('/api*', function(req, res){
641642
res.send(req.params[0]);
642643
});
643644

644645
request(app)
645-
.get('/api')
646-
.expect('', function(){
647-
request(app)
646+
.get('/api')
647+
.expect(200, '', cb)
648+
649+
request(app)
648650
.get('/api/hey')
649-
.expect('/hey', done);
650-
});
651+
.expect(200, '/hey', cb)
651652
})
652653

653654
it('should allow naming', function(done){
@@ -863,36 +864,38 @@ describe('app.router', function(){
863864
describe('.:name', function(){
864865
it('should denote a format', function(done){
865866
var app = express();
867+
var cb = after(2, done)
866868

867869
app.get('/:name.:format', function(req, res){
868870
res.end(req.params.name + ' as ' + req.params.format);
869871
});
870872

871873
request(app)
872-
.get('/foo.json')
873-
.expect('foo as json', function(){
874-
request(app)
874+
.get('/foo.json')
875+
.expect(200, 'foo as json', cb)
876+
877+
request(app)
875878
.get('/foo')
876-
.expect(404, done);
877-
});
879+
.expect(404, cb)
878880
})
879881
})
880882

881883
describe('.:name?', function(){
882884
it('should denote an optional format', function(done){
883885
var app = express();
886+
var cb = after(2, done)
884887

885888
app.get('/:name.:format?', function(req, res){
886889
res.end(req.params.name + ' as ' + (req.params.format || 'html'));
887890
});
888891

889892
request(app)
890-
.get('/foo')
891-
.expect('foo as html', function(){
892-
request(app)
893+
.get('/foo')
894+
.expect(200, 'foo as html', cb)
895+
896+
request(app)
893897
.get('/foo.json')
894-
.expect('foo as json', done);
895-
});
898+
.expect(200, 'foo as json', done)
896899
})
897900
})
898901

test/app.use.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('app', function(){
3737
var blog = express()
3838
, forum = express()
3939
, app = express();
40+
var cb = after(2, done)
4041

4142
blog.get('/', function(req, res){
4243
res.end('blog');
@@ -50,12 +51,12 @@ describe('app', function(){
5051
app.use('/forum', forum);
5152

5253
request(app)
53-
.get('/blog')
54-
.expect('blog', function(){
55-
request(app)
54+
.get('/blog')
55+
.expect(200, 'blog', cb)
56+
57+
request(app)
5658
.get('/forum')
57-
.expect('forum', done);
58-
});
59+
.expect(200, 'forum', done)
5960
})
6061

6162
it('should set the child\'s .parent', function(){

0 commit comments

Comments
 (0)