2014-03-05 22:06:14 -08:00
|
|
|
var express = require('../');
|
|
|
|
|
var request = require('supertest');
|
2014-02-23 11:31:43 -05:00
|
|
|
|
|
|
|
|
describe('app.route', function(){
|
|
|
|
|
it('should return a new route', function(done){
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
|
|
app.route('/foo')
|
|
|
|
|
.get(function(req, res) {
|
|
|
|
|
res.send('get');
|
|
|
|
|
})
|
|
|
|
|
.post(function(req, res) {
|
|
|
|
|
res.send('post');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
|
.post('/foo')
|
|
|
|
|
.expect('post', done);
|
|
|
|
|
});
|
2014-03-03 17:50:13 -05:00
|
|
|
|
|
|
|
|
it('should all .VERB after .all', function(done){
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
|
|
app.route('/foo')
|
|
|
|
|
.all(function(req, res, next) {
|
|
|
|
|
next();
|
|
|
|
|
})
|
|
|
|
|
.get(function(req, res) {
|
|
|
|
|
res.send('get');
|
|
|
|
|
})
|
|
|
|
|
.post(function(req, res) {
|
|
|
|
|
res.send('post');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
|
.post('/foo')
|
|
|
|
|
.expect('post', done);
|
|
|
|
|
});
|
2014-03-10 13:16:39 -04:00
|
|
|
|
|
|
|
|
it('should support dynamic routes', function(done){
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
|
|
app.route('/:foo')
|
|
|
|
|
.get(function(req, res) {
|
|
|
|
|
res.send(req.params.foo);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
|
.get('/test')
|
|
|
|
|
.expect('test', done);
|
|
|
|
|
});
|
2014-06-06 11:12:52 -04:00
|
|
|
|
|
|
|
|
it('should not error on empty routes', function(done){
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
|
|
app.route('/:foo');
|
|
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
|
.get('/test')
|
|
|
|
|
.expect(404, done);
|
|
|
|
|
});
|
2014-02-23 11:31:43 -05:00
|
|
|
});
|