@@ -566,6 +566,76 @@ describe('Request', function () {
566566 expect ( res . body . file ) . to . equal ( true )
567567 } )
568568
569+ it ( 'should return true when a pattern matches the current route url' , function * ( ) {
570+ const server = http . createServer ( function ( req , res ) {
571+ const request = new Request ( req , res , Config )
572+ const matches = request . match ( '/user/:id/profile' )
573+ res . writeHead ( 200 , { "Content-type" :"application/json" } )
574+ res . end ( JSON . stringify ( { matches} ) , 'utf8' )
575+ } )
576+
577+ const res = yield supertest ( server ) . get ( "/user/1/profile" ) . expect ( 200 ) . end ( )
578+ expect ( res . body . matches ) . to . equal ( true )
579+ } )
580+
581+ it ( 'should return false when a pattern does not matches the current route url' , function * ( ) {
582+ const server = http . createServer ( function ( req , res ) {
583+ const request = new Request ( req , res , Config )
584+ const matches = request . match ( '/user' )
585+ res . writeHead ( 200 , { "Content-type" :"application/json" } )
586+ res . end ( JSON . stringify ( { matches} ) , 'utf8' )
587+ } )
588+
589+ const res = yield supertest ( server ) . get ( "/user/1/profile" ) . expect ( 200 ) . end ( )
590+ expect ( res . body . matches ) . to . equal ( false )
591+ } )
592+
593+ it ( 'should return true when any of the paths inside array matches the current route url' , function * ( ) {
594+ const server = http . createServer ( function ( req , res ) {
595+ const request = new Request ( req , res , Config )
596+ const matches = request . match ( [ '/user' , '/user/1/profile' ] )
597+ res . writeHead ( 200 , { "Content-type" :"application/json" } )
598+ res . end ( JSON . stringify ( { matches} ) , 'utf8' )
599+ } )
600+ const res = yield supertest ( server ) . get ( "/user/1/profile" ) . expect ( 200 ) . end ( )
601+ expect ( res . body . matches ) . to . equal ( true )
602+ } )
603+
604+ it ( 'should return false when none of the paths inside array matches the current route url' , function * ( ) {
605+ const server = http . createServer ( function ( req , res ) {
606+ const request = new Request ( req , res , Config )
607+ const matches = request . match ( [ '/user' , '/user/1' , '/1/profile' ] )
608+ res . writeHead ( 200 , { "Content-type" :"application/json" } )
609+ res . end ( JSON . stringify ( { matches} ) , 'utf8' )
610+ } )
611+ const res = yield supertest ( server ) . get ( "/user/1/profile" ) . expect ( 200 ) . end ( )
612+ expect ( res . body . matches ) . to . equal ( false )
613+ } )
614+
615+ it ( 'should return true when any of the paths from any of the arguments matches the current route url' , function * ( ) {
616+ const server = http . createServer ( function ( req , res ) {
617+ const request = new Request ( req , res , Config )
618+ const matches = request . match ( '/user' , '/user/1/profile' )
619+ res . writeHead ( 200 , { "Content-type" :"application/json" } )
620+ res . end ( JSON . stringify ( { matches} ) , 'utf8' )
621+ } )
622+
623+ const res = yield supertest ( server ) . get ( "/user/1/profile" ) . expect ( 200 ) . end ( )
624+ expect ( res . body . matches ) . to . equal ( true )
625+ } )
626+
627+ it ( 'should return false when any of the paths from any of the arguments does not matches the current route url' , function * ( ) {
628+ const server = http . createServer ( function ( req , res ) {
629+ const request = new Request ( req , res , Config )
630+ const matches = request . match ( '/user' , '/user/1' , '/user/profile' )
631+ res . writeHead ( 200 , { "Content-type" :"application/json" } )
632+ res . end ( JSON . stringify ( { matches} ) , 'utf8' )
633+ } )
634+
635+ const res = yield supertest ( server ) . get ( "/user/1/profile" ) . expect ( 200 ) . end ( )
636+ expect ( res . body . matches ) . to . equal ( false )
637+ } )
638+
569639 it ( 'should return an empty file instance when file is not uploaded' , function * ( ) {
570640 const server = http . createServer ( function ( req , res ) {
571641 var form = new formidable . IncomingForm ( ) ;
0 commit comments