@@ -1048,6 +1048,27 @@ describe('Router#use()', () => {
10481048 assert . strictEqual ( res . body . foobar , 'foobar' ) ;
10491049 } ) ;
10501050
1051+ it ( 'uses router middleware at given path with parameters - koajs/router#gh-202' , async ( ) => {
1052+ const app = new Koa ( ) ;
1053+ const router = new Router ( ) ;
1054+ router . use ( '/:foo/:bar' , ( ctx , next ) => {
1055+ ctx . foo = ctx . params . foo ;
1056+ ctx . bar = ctx . params . bar ;
1057+ return next ( ) ;
1058+ } ) ;
1059+ router . get ( '/:foo/:bar' , ( ctx ) => {
1060+ ctx . body = {
1061+ foobar : ctx . foo + ctx . bar
1062+ } ;
1063+ } ) ;
1064+ app . use ( router . routes ( ) ) ;
1065+ const res = await request ( http . createServer ( app . callback ( ) ) )
1066+ . get ( '/qux/baz' )
1067+ . expect ( 200 ) ;
1068+
1069+ assert . strictEqual ( res . body . foobar , 'quxbaz' ) ;
1070+ } ) ;
1071+
10511072 it ( 'runs router middleware before subrouter middleware' , async ( ) => {
10521073 const app = new Koa ( ) ;
10531074 const router = new Router ( ) ;
@@ -1911,17 +1932,20 @@ describe('Router#prefix', () => {
19111932 assert . strictEqual ( 'params' in ctx , true ) ;
19121933 assert . strictEqual ( typeof ctx . params , 'object' ) ;
19131934 assert . strictEqual ( ctx . params . category , 'cats' ) ;
1935+ ctx . category = ctx . params . category ;
19141936 return next ( ) ;
19151937 } )
19161938 . get ( '/suffixHere' , ( ctx ) => {
19171939 assert . strictEqual ( 'params' in ctx , true ) ;
19181940 assert . strictEqual ( typeof ctx . params , 'object' ) ;
19191941 assert . strictEqual ( ctx . params . category , 'cats' ) ;
1920- ctx . status = 204 ;
1942+ ctx . status = 200 ;
1943+ ctx . body = ctx . category ;
19211944 } ) ;
1922- await request ( http . createServer ( app . callback ( ) ) )
1945+ const res = await request ( http . createServer ( app . callback ( ) ) )
19231946 . get ( '/cats/suffixHere' )
1924- . expect ( 204 ) ;
1947+ . expect ( 200 ) ;
1948+ assert . strictEqual ( res . text , 'cats' ) ;
19251949 } ) ;
19261950
19271951 it ( 'populates ctx.params correctly for more complex router prefix (including use)' , async ( ) => {
0 commit comments