@@ -208,6 +208,37 @@ describe("UrlRouter", function () {
208208 expect ( router . locationService . url ) . toHaveBeenCalledWith ( "/hello/" , undefined ) ;
209209 } ) ) ;
210210
211+ it ( 'can push an empty url' , inject ( function ( $urlRouter , $location ) {
212+ spyOn ( router . locationService , "url" ) ;
213+ $urlRouter . push ( $umf . compile ( '/{id}' , { params : { id : { squash : true , value : null } } } ) ) ;
214+ expect ( router . locationService . url ) . toHaveBeenCalledWith ( "" , undefined ) ;
215+ } ) ) ;
216+
217+ // Angular 1.2 doesn't seem to support $location.url("")
218+ if ( angular . version . minor >= 3 ) {
219+ // Test for https://github.com/angular-ui/ui-router/issues/3563
220+ it ( 'updates url after an empty url is pushed' , inject ( function ( $urlRouter , $location ) {
221+ $lp . html5Mode ( false ) ;
222+ spyOn ( router . locationService , "url" ) . and . callThrough ( ) ;
223+ $urlRouter . push ( $umf . compile ( '/foobar' ) ) ;
224+ expect ( router . locationService . url ) . toHaveBeenCalledWith ( "/foobar" , undefined ) ;
225+ $urlRouter . push ( $umf . compile ( '/{id}' , { params : { id : { squash : true , value : null } } } ) ) ;
226+ expect ( router . locationService . url ) . toHaveBeenCalledWith ( "" , undefined ) ;
227+ expect ( router . locationService . url ( ) ) . toBe ( '/' ) ;
228+ } ) ) ;
229+
230+ // Test #2 for https://github.com/angular-ui/ui-router/issues/3563
231+ it ( 'updates html5mode url after an empty url is pushed' , inject ( function ( $urlRouter , $location ) {
232+ $lp . html5Mode ( true ) ;
233+ spyOn ( router . locationService , "url" ) . and . callThrough ( ) ;
234+ $urlRouter . push ( $umf . compile ( '/foobar' ) ) ;
235+ expect ( router . locationService . url ) . toHaveBeenCalledWith ( "/foobar" , undefined ) ;
236+ $urlRouter . push ( $umf . compile ( '/{id}' , { params : { id : { squash : true , value : null } } } ) ) ;
237+ expect ( router . locationService . url ) . toHaveBeenCalledWith ( "" , undefined ) ;
238+ expect ( router . locationService . url ( ) ) . toBe ( '/' ) ;
239+ } ) ) ;
240+ }
241+
211242 it ( 'can push location changes that include a #fragment' , inject ( function ( $urlRouter , $location ) {
212243 // html5mode disabled
213244 $lp . html5Mode ( false ) ;
0 commit comments