@@ -303,5 +303,65 @@ describe('app', function(){
303303 . get ( '/user/new' )
304304 . expect ( 'get.new' , done ) ;
305305 } )
306+
307+ it ( 'should not call when values differ on error' , function ( done ) {
308+ var app = express ( ) ;
309+ var called = 0 ;
310+ var count = 0 ;
311+
312+ app . param ( 'user' , function ( req , res , next , user ) {
313+ called ++ ;
314+ if ( user === 'foo' ) throw new Error ( 'err!' ) ;
315+ req . user = user ;
316+ next ( ) ;
317+ } ) ;
318+
319+ app . get ( '/:user/bob' , function ( req , res , next ) {
320+ count ++ ;
321+ next ( ) ;
322+ } ) ;
323+ app . get ( '/foo/:user' , function ( req , res , next ) {
324+ count ++ ;
325+ next ( ) ;
326+ } ) ;
327+
328+ app . use ( function ( err , req , res , next ) {
329+ res . status ( 500 ) ;
330+ res . send ( [ count , called , err . message ] . join ( ' ' ) ) ;
331+ } ) ;
332+
333+ request ( app )
334+ . get ( '/foo/bob' )
335+ . expect ( 500 , '0 1 err!' , done )
336+ } ) ;
337+
338+ it ( 'should call when values differ when using "next"' , function ( done ) {
339+ var app = express ( ) ;
340+ var called = 0 ;
341+ var count = 0 ;
342+
343+ app . param ( 'user' , function ( req , res , next , user ) {
344+ called ++ ;
345+ if ( user === 'foo' ) return next ( 'route' ) ;
346+ req . user = user ;
347+ next ( ) ;
348+ } ) ;
349+
350+ app . get ( '/:user/bob' , function ( req , res , next ) {
351+ count ++ ;
352+ next ( ) ;
353+ } ) ;
354+ app . get ( '/foo/:user' , function ( req , res , next ) {
355+ count ++ ;
356+ next ( ) ;
357+ } ) ;
358+ app . use ( function ( req , res ) {
359+ res . end ( [ count , called , req . user ] . join ( ' ' ) ) ;
360+ } ) ;
361+
362+ request ( app )
363+ . get ( '/foo/bob' )
364+ . expect ( '1 2 bob' , done ) ;
365+ } )
306366 } )
307367} )
0 commit comments