Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit 11982b1

Browse files
test(urlRouter): avoid using jasmine toHaveBeenCalledWith because it doesn't play well with undefined arguments
1 parent 2e7982f commit 11982b1

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

test/urlRouterSpec.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,50 +198,54 @@ describe('UrlRouter', function() {
198198

199199
describe('___location updates', function() {
200200
it('can push ___location changes', inject(function($urlRouter) {
201-
spyOn(router.locationService, 'url');
201+
const spy = spyOn(router.locationService, 'url');
202202
$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');
204205
}));
205206

206207
it('can push a replacement ___location', inject(function($urlRouter, $___location) {
207-
spyOn(router.locationService, 'url');
208+
const spy = spyOn(router.locationService, 'url');
208209
$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]);
210212
}));
211213

212214
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/');
216219
}));
217220

218221
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('');
222226
}));
223227

224228
// Angular 1.2 doesn't seem to support $___location.url("")
225229
if (angular.version.minor >= 3) {
226230
// Test for https://github.com/angular-ui/ui-router/issues/3563
227231
it('updates url after an empty url is pushed', inject(function($urlRouter, $___location) {
228232
$lp.html5Mode(false);
229-
spyOn(router.locationService, 'url').and.callThrough();
233+
const spy = spyOn(router.locationService, 'url').and.callThrough();
230234
$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('');
234238
expect(router.locationService.url()).toBe('/');
235239
}));
236240

237241
// Test #2 for https://github.com/angular-ui/ui-router/issues/3563
238242
it('updates html5mode url after an empty url is pushed', inject(function($urlRouter, $___location) {
239243
$lp.html5Mode(true);
240-
spyOn(router.locationService, 'url').and.callThrough();
244+
const spy = spyOn(router.locationService, 'url').and.callThrough();
241245
$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('');
245249
expect(router.locationService.url()).toBe('/');
246250
}));
247251
}

0 commit comments

Comments
 (0)