Skip to content

Commit

Permalink
tests: fix tests that did not bubble errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 2, 2022
1 parent bd4fdfe commit 141914e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
12 changes: 7 additions & 5 deletions test/app.all.js
Original file line number Diff line number Diff line change
@@ -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){
Expand Down
15 changes: 6 additions & 9 deletions test/app.head.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
33 changes: 18 additions & 15 deletions test/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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)
})
})

Expand Down
11 changes: 6 additions & 5 deletions test/app.use.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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(){
Expand Down

0 comments on commit 141914e

Please sign in to comment.