3 var express
= require('../');
4 var request
= require('supertest');
6 var describePromises
= global
.Promise
? describe
: describe
.skip
8 describe('app.route', function(){
9 it('should return a new route', function(done
){
13 .get(function(req
, res
) {
16 .post(function(req
, res
) {
22 .expect('post', done
);
25 it('should all .VERB after .all', function(done
){
29 .all(function(req
, res
, next
) {
32 .get(function(req
, res
) {
35 .post(function(req
, res
) {
41 .expect('post', done
);
44 it('should support dynamic routes', function(done
){
48 .get(function(req
, res
) {
49 res
.send(req
.params
.foo
);
54 .expect('test', done
);
57 it('should not error on empty routes', function(done
){
67 describePromises('promise support', function () {
68 it('should pass rejected promise value', function (done
) {
70 var route
= app
.route('/foo')
72 route
.all(function createError (req
, res
, next
) {
73 return Promise
.reject(new Error('boom!'))
76 route
.all(function helloWorld (req
, res
) {
77 res
.send('hello, world!')
80 route
.all(function handleError (err
, req
, res
, next
) {
82 res
.send('caught: ' + err
.message
)
87 .expect(500, 'caught: boom!', done
)
90 it('should pass rejected promise without value', function (done
) {
92 var route
= app
.route('/foo')
94 route
.all(function createError (req
, res
, next
) {
95 return Promise
.reject()
98 route
.all(function helloWorld (req
, res
) {
99 res
.send('hello, world!')
102 route
.all(function handleError (err
, req
, res
, next
) {
104 res
.send('caught: ' + err
.message
)
109 .expect(500, 'caught: Rejected promise', done
)
112 it('should ignore resolved promise', function (done
) {
114 var route
= app
.route('/foo')
116 route
.all(function createError (req
, res
, next
) {
117 res
.send('saw GET /foo')
118 return Promise
.resolve('foo')
121 route
.all(function () {
122 done(new Error('Unexpected route invoke'))
127 .expect(200, 'saw GET /foo', done
)
130 describe('error handling', function () {
131 it('should pass rejected promise value', function (done
) {
133 var route
= app
.route('/foo')
135 route
.all(function createError (req
, res
, next
) {
136 return Promise
.reject(new Error('boom!'))
139 route
.all(function handleError (err
, req
, res
, next
) {
140 return Promise
.reject(new Error('caught: ' + err
.message
))
143 route
.all(function handleError (err
, req
, res
, next
) {
145 res
.send('caught again: ' + err
.message
)
150 .expect(500, 'caught again: caught: boom!', done
)
153 it('should pass rejected promise without value', function (done
) {
155 var route
= app
.route('/foo')
157 route
.all(function createError (req
, res
, next
) {
158 return Promise
.reject(new Error('boom!'))
161 route
.all(function handleError (err
, req
, res
, next
) {
162 return Promise
.reject()
165 route
.all(function handleError (err
, req
, res
, next
) {
167 res
.send('caught again: ' + err
.message
)
172 .expect(500, 'caught again: Rejected promise', done
)
175 it('should ignore resolved promise', function (done
) {
177 var route
= app
.route('/foo')
179 route
.all(function createError (req
, res
, next
) {
180 return Promise
.reject(new Error('boom!'))
183 route
.all(function handleError (err
, req
, res
, next
) {
185 res
.send('caught: ' + err
.message
)
186 return Promise
.resolve('foo')
189 route
.all(function () {
190 done(new Error('Unexpected route invoke'))
195 .expect(500, 'caught: boom!', done
)