@@ -61,6 +61,20 @@ describe('Path.extractParams', function () {
6161 } ) ;
6262 } ) ;
6363 } ) ;
64+ describe ( 'and the pattern and forward slash are optional' , function ( ) {
65+ var pattern = 'comments/:id?/edit'
66+
67+ describe ( 'and the path matches with supplied param' , function ( ) {
68+ it ( 'returns an object with the params' , function ( ) {
69+ expect ( Path . extractParams ( pattern , 'comments/123/edit' ) ) . toEqual ( { id : '123' } ) ;
70+ } ) ;
71+ } ) ;
72+ describe ( 'and the path matches without supplied param' , function ( ) {
73+ it ( 'returns an object with param set to null' , function ( ) {
74+ expect ( Path . extractParams ( pattern , 'comments/edit' ) ) . toEqual ( { id : null } ) ;
75+ } ) ;
76+ } ) ;
77+ } ) ;
6478 describe ( 'and the path does not match' , function ( ) {
6579 it ( 'returns null' , function ( ) {
6680 expect ( Path . extractParams ( pattern , 'users/123' ) ) . toBe ( null ) ;
@@ -192,6 +206,18 @@ describe('Path.injectParams', function () {
192206 } ) ;
193207 } ) ;
194208
209+ describe ( 'and a param and forward slash are optional' , function ( ) {
210+ var pattern = 'comments/:id?/?edit' ;
211+
212+ it ( 'returns the correct path when param is supplied' , function ( ) {
213+ expect ( Path . injectParams ( pattern , { id :'123' } ) ) . toEqual ( 'comments/123/edit' ) ;
214+ } ) ;
215+
216+ it ( 'returns the correct path when param is not supplied' , function ( ) {
217+ expect ( Path . injectParams ( pattern , { } ) ) . toEqual ( 'comments/edit' ) ;
218+ } ) ;
219+ } ) ;
220+
195221 describe ( 'and all params are present' , function ( ) {
196222 it ( 'returns the correct path' , function ( ) {
197223 expect ( Path . injectParams ( pattern , { id : 'abc' } ) ) . toEqual ( 'comments/abc/edit' ) ;
0 commit comments