From 141914e8172f5d1a08825fc60a54d944121b1ec0 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 14:16:20 -0500 Subject: [PATCH] tests: fix tests that did not bubble errors --- test/app.all.js | 12 +++++++----- test/app.head.js | 15 ++++++--------- test/app.router.js | 33 ++++++++++++++++++--------------- test/app.use.js | 11 ++++++----- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/test/app.all.js b/test/app.all.js index e9ef08831d..45c3ddb93b 100644 --- a/test/app.all.js +++ b/test/app.all.js @@ -1,22 +1,24 @@ +var after = require('after') var express = require('../') , request = require('supertest'); describe('app.all()', function(){ it('should add a router per method', function(done){ var app = express(); + var cb = after(2, done) app.all('/tobi', function(req, res){ res.end(req.method); }); request(app) - .put('/tobi') - .expect('PUT', function(){ - request(app) + .put('/tobi') + .expect(200, 'PUT', cb) + + request(app) .get('/tobi') - .expect('GET', done); - }); + .expect(200, 'GET', cb) }) it('should run the callback for a method just once', function(done){ diff --git a/test/app.head.js b/test/app.head.js index b417ca0c92..6aa1bb8003 100644 --- a/test/app.head.js +++ b/test/app.head.js @@ -46,23 +46,20 @@ describe('HEAD', function(){ describe('app.head()', function(){ it('should override', function(done){ var app = express() - , called; app.head('/tobi', function(req, res){ - called = true; - res.end(''); + res.header('x-method', 'head') + res.end() }); app.get('/tobi', function(req, res){ - assert(0, 'should not call GET'); + res.header('x-method', 'get') res.send('tobi'); }); request(app) - .head('/tobi') - .expect(200, function(){ - assert(called); - done(); - }); + .head('/tobi') + .expect('x-method', 'head') + .expect(200, done) }) }) diff --git a/test/app.router.js b/test/app.router.js index 6edb93d6ea..8c98aa869b 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -636,18 +636,19 @@ describe('app.router', function(){ it('should work cross-segment', function(done){ var app = express(); + var cb = after(2, done) app.get('/api*', function(req, res){ res.send(req.params[0]); }); request(app) - .get('/api') - .expect('', function(){ - request(app) + .get('/api') + .expect(200, '', cb) + + request(app) .get('/api/hey') - .expect('/hey', done); - }); + .expect(200, '/hey', cb) }) it('should allow naming', function(done){ @@ -863,36 +864,38 @@ describe('app.router', function(){ describe('.:name', function(){ it('should denote a format', function(done){ var app = express(); + var cb = after(2, done) app.get('/:name.:format', function(req, res){ res.end(req.params.name + ' as ' + req.params.format); }); request(app) - .get('/foo.json') - .expect('foo as json', function(){ - request(app) + .get('/foo.json') + .expect(200, 'foo as json', cb) + + request(app) .get('/foo') - .expect(404, done); - }); + .expect(404, cb) }) }) describe('.:name?', function(){ it('should denote an optional format', function(done){ var app = express(); + var cb = after(2, done) app.get('/:name.:format?', function(req, res){ res.end(req.params.name + ' as ' + (req.params.format || 'html')); }); request(app) - .get('/foo') - .expect('foo as html', function(){ - request(app) + .get('/foo') + .expect(200, 'foo as html', cb) + + request(app) .get('/foo.json') - .expect('foo as json', done); - }); + .expect(200, 'foo as json', done) }) }) diff --git a/test/app.use.js b/test/app.use.js index 7987405a8b..55ba0689c8 100644 --- a/test/app.use.js +++ b/test/app.use.js @@ -37,6 +37,7 @@ describe('app', function(){ var blog = express() , forum = express() , app = express(); + var cb = after(2, done) blog.get('/', function(req, res){ res.end('blog'); @@ -50,12 +51,12 @@ describe('app', function(){ app.use('/forum', forum); request(app) - .get('/blog') - .expect('blog', function(){ - request(app) + .get('/blog') + .expect(200, 'blog', cb) + + request(app) .get('/forum') - .expect('forum', done); - }); + .expect(200, 'forum', done) }) it('should set the child\'s .parent', function(){