@@ -198,50 +198,54 @@ describe('UrlRouter', function() {
198
198
199
199
describe ( '___location updates' , function ( ) {
200
200
it ( 'can push ___location changes' , inject ( function ( $urlRouter ) {
201
- spyOn ( router . locationService , 'url' ) ;
201
+ const spy = spyOn ( router . locationService , 'url' ) ;
202
202
$urlRouter . push ( $umf . compile ( '/hello/:name' ) , { name : 'world' } ) ;
203
- expect ( router . locationService . url ) . toHaveBeenCalledWith ( '/hello/world' , undefined ) ;
203
+ expect ( spy ) . toHaveBeenCalled ( ) ;
204
+ expect ( spy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( '/hello/world' ) ;
204
205
} ) ) ;
205
206
206
207
it ( 'can push a replacement ___location' , inject ( function ( $urlRouter , $___location ) {
207
- spyOn ( router . locationService , 'url' ) ;
208
+ const spy = spyOn ( router . locationService , 'url' ) ;
208
209
$urlRouter . push ( $umf . compile ( '/hello/:name' ) , { name : 'world' } , { replace : true } ) ;
209
- expect ( router . locationService . url ) . toHaveBeenCalledWith ( '/hello/world' , true ) ;
210
+ expect ( spy ) . toHaveBeenCalled ( ) ;
211
+ expect ( spy . calls . mostRecent ( ) . args . slice ( 0 , 2 ) ) . toEqual ( [ '/hello/world' , true ] ) ;
210
212
} ) ) ;
211
213
212
214
it ( 'can push ___location changes with no parameters' , inject ( function ( $urlRouter , $___location ) {
213
- spyOn ( router . locationService , 'url' ) ;
214
- $urlRouter . push ( $umf . compile ( '/hello/:name' , { params : { name : '' } } ) ) ;
215
- expect ( router . locationService . url ) . toHaveBeenCalledWith ( '/hello/' , undefined ) ;
215
+ const spy = spyOn ( router . locationService , 'url' ) ;
216
+ $urlRouter . push ( $umf . compile ( '/hello/:name' , { state : { params : { name : '' } } } ) ) ;
217
+ expect ( spy ) . toHaveBeenCalled ( ) ;
218
+ expect ( spy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( '/hello/' ) ;
216
219
} ) ) ;
217
220
218
221
it ( 'can push an empty url' , inject ( function ( $urlRouter , $___location ) {
219
- spyOn ( router . locationService , 'url' ) ;
220
- $urlRouter . push ( $umf . compile ( '/{id}' , { params : { id : { squash : true , value : null } } } ) ) ;
221
- expect ( router . locationService . url ) . toHaveBeenCalledWith ( '' , undefined ) ;
222
+ const spy = spyOn ( router . locationService , 'url' ) ;
223
+ $urlRouter . push ( $umf . compile ( '/{id}' , { state : { params : { id : { squash : true , value : null } } } } ) ) ;
224
+ expect ( spy ) . toHaveBeenCalled ( ) ;
225
+ expect ( spy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( '' ) ;
222
226
} ) ) ;
223
227
224
228
// Angular 1.2 doesn't seem to support $___location.url("")
225
229
if ( angular . version . minor >= 3 ) {
226
230
// Test for https://github.com/angular-ui/ui-router/issues/3563
227
231
it ( 'updates url after an empty url is pushed' , inject ( function ( $urlRouter , $___location ) {
228
232
$lp . html5Mode ( false ) ;
229
- spyOn ( router . locationService , 'url' ) . and . callThrough ( ) ;
233
+ const spy = spyOn ( router . locationService , 'url' ) . and . callThrough ( ) ;
230
234
$urlRouter . push ( $umf . compile ( '/foobar' ) ) ;
231
- expect ( router . locationService . url ) . toHaveBeenCalledWith ( '/foobar' , undefined ) ;
232
- $urlRouter . push ( $umf . compile ( '/{id}' , { params : { id : { squash : true , value : null } } } ) ) ;
233
- expect ( router . locationService . url ) . toHaveBeenCalledWith ( '' , undefined ) ;
235
+ expect ( spy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( '/foobar' ) ;
236
+ $urlRouter . push ( $umf . compile ( '/{id}' , { state : { params : { id : { squash : true , value : null } } } } ) ) ;
237
+ expect ( spy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( '' ) ;
234
238
expect ( router . locationService . url ( ) ) . toBe ( '/' ) ;
235
239
} ) ) ;
236
240
237
241
// Test #2 for https://github.com/angular-ui/ui-router/issues/3563
238
242
it ( 'updates html5mode url after an empty url is pushed' , inject ( function ( $urlRouter , $___location ) {
239
243
$lp . html5Mode ( true ) ;
240
- spyOn ( router . locationService , 'url' ) . and . callThrough ( ) ;
244
+ const spy = spyOn ( router . locationService , 'url' ) . and . callThrough ( ) ;
241
245
$urlRouter . push ( $umf . compile ( '/foobar' ) ) ;
242
- expect ( router . locationService . url ) . toHaveBeenCalledWith ( '/foobar' , undefined ) ;
243
- $urlRouter . push ( $umf . compile ( '/{id}' , { params : { id : { squash : true , value : null } } } ) ) ;
244
- expect ( router . locationService . url ) . toHaveBeenCalledWith ( '' , undefined ) ;
246
+ expect ( spy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( '/foobar' ) ;
247
+ $urlRouter . push ( $umf . compile ( '/{id}' , { state : { params : { id : { squash : true , value : null } } } } ) ) ;
248
+ expect ( spy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( '' ) ;
245
249
expect ( router . locationService . url ( ) ) . toBe ( '/' ) ;
246
250
} ) ) ;
247
251
}
0 commit comments