From a1c3be21ecdea9cfc820de14abe68ca4c792cc6e Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 17 Feb 2016 07:47:49 +0000 Subject: [PATCH] fix(angular1_router): rename `$route` service to `$rootRouter` The singleton service that represents the top level router was called `$router` but this is confusing since there are actually lots of routers, which depend upon where you are in the DOM. This is similar to the situation with scopes. This commit clarifies this singleton by renaming it to `$rootRouter`. BREAKING CHANGE: The `$router` injectable service has been renamed to `$rootRouter` --- modules/angular1_router/index.html | 6 +- .../angular1_router/src/module_template.js | 2 +- modules/angular1_router/src/ng_outlet.ts | 20 ++-- modules/angular1_router/src/ng_route_shim.js | 14 +-- .../test/integration/animation_spec.js | 12 +-- .../test/integration/lifecycle_hook_spec.js | 92 +++++++++---------- .../test/integration/navigation_spec.js | 70 +++++++------- .../test/integration/router_spec.js | 6 +- .../test/integration/shim_spec.js | 24 ++--- modules/angular1_router/test/ng_link_spec.js | 30 +++--- modules/angular1_router/test/util.es5.js | 8 +- 11 files changed, 141 insertions(+), 143 deletions(-) diff --git a/modules/angular1_router/index.html b/modules/angular1_router/index.html index 28395c361e..5927dee811 100644 --- a/modules/angular1_router/index.html +++ b/modules/angular1_router/index.html @@ -12,9 +12,9 @@ diff --git a/modules/angular1_router/src/module_template.js b/modules/angular1_router/src/module_template.js index 0139664bc7..072f545c6d 100644 --- a/modules/angular1_router/src/module_template.js +++ b/modules/angular1_router/src/module_template.js @@ -4,7 +4,7 @@ angular.module('ngComponentRouter'). // Because Angular 1 has no notion of a root component, we use an object with unique identity // to represent this. Can be overloaded with a component name value('$routerRootComponent', new Object()). - factory('$router', ['$q', '$location', '$$directiveIntrospector', '$browser', '$rootScope', '$injector', '$routerRootComponent', routerFactory]); + factory('$rootRouter', ['$q', '$location', '$$directiveIntrospector', '$browser', '$rootScope', '$injector', '$routerRootComponent', routerFactory]); function routerFactory($q, $location, $$directiveIntrospector, $browser, $rootScope, $injector, $routerRootComponent) { diff --git a/modules/angular1_router/src/ng_outlet.ts b/modules/angular1_router/src/ng_outlet.ts index 7572d92ff2..1fdfeac150 100644 --- a/modules/angular1_router/src/ng_outlet.ts +++ b/modules/angular1_router/src/ng_outlet.ts @@ -61,8 +61,8 @@ class DirectiveIntrospectorProvider { * * The value for the `ngOutlet` attribute is optional. */ -function ngOutletDirective($animate, $q: ng.IQService, $router) { - let rootRouter = $router; +function ngOutletDirective($animate, $q: ng.IQService, $rootRouter) { + let rootRouter = $rootRouter; return { restrict: 'AE', @@ -231,8 +231,8 @@ function routerTriggerDirective($q) { * * ```js * angular.module('myApp', ['ngComponentRouter']) - * .controller('AppController', ['$router', function($router) { - * $router.config({ path: '/user/:id', component: 'user' }); + * .controller('AppController', ['$rootRouter', function($rootRouter) { + * $rootRouter.config({ path: '/user/:id', component: 'user' }); * this.user = { name: 'Brian', id: 123 }; * }); * ``` @@ -243,13 +243,11 @@ function routerTriggerDirective($q) { * * ``` */ -function ngLinkDirective($router, $parse) { - let rootRouter = $router; - +function ngLinkDirective($rootRouter, $parse) { return {require: '?^^ngOutlet', restrict: 'A', link: ngLinkDirectiveLinkFn}; function ngLinkDirectiveLinkFn(scope, element, attrs, ctrl) { - let router = (ctrl && ctrl.$$router) || rootRouter; + let router = (ctrl && ctrl.$$router) || $rootRouter; if (!router) { return; } @@ -277,7 +275,7 @@ function ngLinkDirective($router, $parse) { return; } - $router.navigateByInstruction(instruction); + $rootRouter.navigateByInstruction(instruction); event.preventDefault(); }); } @@ -291,9 +289,9 @@ function dashCase(str: string): string { * A module for adding new a routing system Angular 1. */ angular.module('ngComponentRouter', []) - .directive('ngOutlet', ['$animate', '$q', '$router', ngOutletDirective]) + .directive('ngOutlet', ['$animate', '$q', '$rootRouter', ngOutletDirective]) .directive('ngOutlet', ['$compile', ngOutletFillContentDirective]) - .directive('ngLink', ['$router', '$parse', ngLinkDirective]) + .directive('ngLink', ['$rootRouter', '$parse', ngLinkDirective]) .directive('$router', ['$q', routerTriggerDirective]); /* diff --git a/modules/angular1_router/src/ng_route_shim.js b/modules/angular1_router/src/ng_route_shim.js index b471da3434..bb17d0816f 100644 --- a/modules/angular1_router/src/ng_route_shim.js +++ b/modules/angular1_router/src/ng_route_shim.js @@ -24,12 +24,12 @@ .directive('a', anchorLinkDirective) // Connects the legacy $routeProvider config shim to Component Router's config. - .run(['$route', '$router', function ($route, $router) { + .run(['$route', '$rootRouter', function ($route, $rootRouter) { $route.$$subscribe(function (routeDefinition) { if (!angular.isArray(routeDefinition)) { routeDefinition = [routeDefinition]; } - $router.config(routeDefinition); + $rootRouter.config(routeDefinition); }); }]); @@ -241,12 +241,12 @@ } - function $routeParamsFactory($router, $rootScope) { + function $routeParamsFactory($rootRouter, $rootScope) { // the identity of this object cannot change var paramsObj = {}; $rootScope.$on('$routeChangeSuccess', function () { - var newParams = $router._currentInstruction && $router._currentInstruction.component.params; + var newParams = $rootRouter._currentInstruction && $rootRouter._currentInstruction.component.params; angular.forEach(paramsObj, function (val, name) { delete paramsObj[name]; @@ -262,7 +262,7 @@ /** * Allows normal anchor links to kick off routing. */ - function anchorLinkDirective($router) { + function anchorLinkDirective($rootRouter) { return { restrict: 'E', link: function (scope, element) { @@ -281,8 +281,8 @@ } var href = element.attr(hrefAttrName); - if (href && $router.recognize(href)) { - $router.navigateByUrl(href); + if (href && $rootRouter.recognize(href)) { + $rootRouter.navigateByUrl(href); event.preventDefault(); } }); diff --git a/modules/angular1_router/test/integration/animation_spec.js b/modules/angular1_router/test/integration/animation_spec.js index 1b95b3e556..7ab30b4c19 100644 --- a/modules/angular1_router/test/integration/animation_spec.js +++ b/modules/angular1_router/test/integration/animation_spec.js @@ -5,7 +5,7 @@ describe('ngOutlet animations', function () { $animate, $compile, $rootScope, - $router, + $rootRouter, $compileProvider; beforeEach(function () { @@ -17,11 +17,11 @@ describe('ngOutlet animations', function () { $compileProvider = _$compileProvider_; }); - inject(function (_$animate_, _$compile_, _$rootScope_, _$router_) { + inject(function (_$animate_, _$compile_, _$rootScope_, _$rootRouter_) { $animate = _$animate_; $compile = _$compile_; $rootScope = _$rootScope_; - $router = _$router_; + $rootRouter = _$rootRouter_; }); registerComponent('userCmp', { @@ -41,11 +41,11 @@ describe('ngOutlet animations', function () { compile('
'); - $router.config([ + $rootRouter.config([ { path: '/user/:name', component: 'userCmp' } ]); - $router.navigateByUrl('/user/brian'); + $rootRouter.navigateByUrl('/user/brian'); $rootScope.$digest(); expect(elt.text()).toBe('hello brian'); @@ -54,7 +54,7 @@ describe('ngOutlet animations', function () { expect(item.event).toBe('enter'); // navigate to pete - $router.navigateByUrl('/user/pete'); + $rootRouter.navigateByUrl('/user/pete'); $rootScope.$digest(); expect(elt.text()).toBe('hello pete'); diff --git a/modules/angular1_router/test/integration/lifecycle_hook_spec.js b/modules/angular1_router/test/integration/lifecycle_hook_spec.js index 56a2ac04f6..de9923cc1c 100644 --- a/modules/angular1_router/test/integration/lifecycle_hook_spec.js +++ b/modules/angular1_router/test/integration/lifecycle_hook_spec.js @@ -4,7 +4,7 @@ describe('Navigation lifecycle', function () { var elt, $compile, $rootScope, - $router, + $rootRouter, $compileProvider; beforeEach(function () { @@ -14,10 +14,10 @@ describe('Navigation lifecycle', function () { $compileProvider = _$compileProvider_; }); - inject(function (_$compile_, _$rootScope_, _$router_) { + inject(function (_$compile_, _$rootScope_, _$rootRouter_) { $compile = _$compile_; $rootScope = _$rootScope_; - $router = _$router_; + $rootRouter = _$rootRouter_; }); registerComponent('oneCmp', { @@ -38,12 +38,12 @@ describe('Navigation lifecycle', function () { $routerOnActivate: spy }); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'activateCmp' } ]); compile('
outer {
}
'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(spy).toHaveBeenCalled(); @@ -56,12 +56,12 @@ describe('Navigation lifecycle', function () { $routerOnActivate: spy }); - $router.config([ + $rootRouter.config([ { path: '/user/:name', component: 'userCmp' } ]); compile('
'); - $router.navigateByUrl('/user/brian'); + $rootRouter.navigateByUrl('/user/brian'); $rootScope.$digest(); expect(spy).toHaveBeenCalledWith(instructionFor('userCmp'), undefined); @@ -75,15 +75,15 @@ describe('Navigation lifecycle', function () { $routerOnActivate: spy }); - $router.config([ + $rootRouter.config([ { path: '/user/:name', component: 'oneCmp' }, { path: '/post/:id', component: 'activateCmp' } ]); compile('
'); - $router.navigateByUrl('/user/brian'); + $rootRouter.navigateByUrl('/user/brian'); $rootScope.$digest(); - $router.navigateByUrl('/post/123'); + $rootRouter.navigateByUrl('/post/123'); $rootScope.$digest(); expect(spy).toHaveBeenCalledWith(instructionFor('activateCmp'), instructionFor('oneCmp')); @@ -98,12 +98,12 @@ describe('Navigation lifecycle', function () { } }); - $router.config([ + $rootRouter.config([ { path: '/user', component: 'userCmp' } ]); compile('
'); - $router.navigateByUrl('/user'); + $rootRouter.navigateByUrl('/user'); $rootScope.$digest(); expect(injectedScope).toBeDefined(); @@ -116,15 +116,15 @@ describe('Navigation lifecycle', function () { $routerOnDeactivate: spy }); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'deactivateCmp' }, { path: '/b', component: 'oneCmp' } ]); compile('
'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); - $router.navigateByUrl('/b'); + $rootRouter.navigateByUrl('/b'); $rootScope.$digest(); expect(spy).toHaveBeenCalled(); }); @@ -136,15 +136,15 @@ describe('Navigation lifecycle', function () { $routerOnDeactivate: spy }); - $router.config([ + $rootRouter.config([ { path: '/user/:name', component: 'deactivateCmp' }, { path: '/post/:id', component: 'oneCmp' } ]); compile('
'); - $router.navigateByUrl('/user/brian'); + $rootRouter.navigateByUrl('/user/brian'); $rootScope.$digest(); - $router.navigateByUrl('/post/123'); + $rootRouter.navigateByUrl('/post/123'); $rootScope.$digest(); expect(spy).toHaveBeenCalledWith(instructionFor('oneCmp'), instructionFor('deactivateCmp')); @@ -166,15 +166,15 @@ describe('Navigation lifecycle', function () { } }); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'deactivateCmp' }, { path: '/b', component: 'activateCmp' } ]); compile('outer {
}'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); - $router.navigateByUrl('/b'); + $rootRouter.navigateByUrl('/b'); $rootScope.$digest(); expect(log).toEqual(['deactivate', 'activate']); @@ -203,19 +203,19 @@ describe('Navigation lifecycle', function () { } }); - $router.config([ + $rootRouter.config([ { path: '/on-reuse/:number/...', component: 'reuseCmp' }, { path: '/two', component: 'twoCmp', name: 'Two'} ]); compile('outer {
}'); - $router.navigateByUrl('/on-reuse/1/a'); + $rootRouter.navigateByUrl('/on-reuse/1/a'); $rootScope.$digest(); expect(log).toEqual([]); expect(cmpInstanceCount).toBe(1); expect(elt.text()).toBe('outer { reuse {one} }'); - $router.navigateByUrl('/on-reuse/2/b'); + $rootRouter.navigateByUrl('/on-reuse/2/b'); $rootScope.$digest(); expect(log).toEqual(['reuse: on-reuse/1 -> on-reuse/2']); expect(cmpInstanceCount).toBe(1); @@ -245,19 +245,19 @@ describe('Navigation lifecycle', function () { } }); - $router.config([ + $rootRouter.config([ { path: '/never-reuse/:number/...', component: 'reuseCmp' }, { path: '/two', component: 'twoCmp', name: 'Two'} ]); compile('outer {
}'); - $router.navigateByUrl('/never-reuse/1/a'); + $rootRouter.navigateByUrl('/never-reuse/1/a'); $rootScope.$digest(); expect(log).toEqual([]); expect(cmpInstanceCount).toBe(1); expect(elt.text()).toBe('outer { reuse {one} }'); - $router.navigateByUrl('/never-reuse/2/b'); + $rootRouter.navigateByUrl('/never-reuse/2/b'); $rootScope.$digest(); expect(log).toEqual([]); expect(cmpInstanceCount).toBe(2); @@ -274,12 +274,12 @@ describe('Navigation lifecycle', function () { $routerOnActivate: spy }); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'activateCmp' } ]); compile('outer {
}'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(spy).not.toHaveBeenCalled(); @@ -296,12 +296,12 @@ describe('Navigation lifecycle', function () { $routerOnActivate: activateSpy }); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'activateCmp' } ]); compile('
'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(canActivateSpy).toHaveBeenCalled(); @@ -320,12 +320,12 @@ describe('Navigation lifecycle', function () { $routerOnActivate: spy }); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'activateCmp' } ]); compile('
'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(spy).toHaveBeenCalled(); @@ -341,12 +341,12 @@ describe('Navigation lifecycle', function () { spy.$inject = ['$nextInstruction', '$http']; - $router.config([ + $rootRouter.config([ { path: '/user/:name', component: 'activateCmp' } ]); compile('
'); - $router.navigateByUrl('/user/brian'); + $rootRouter.navigateByUrl('/user/brian'); $rootScope.$digest(); expect(spy).toHaveBeenCalled(); @@ -364,17 +364,17 @@ describe('Navigation lifecycle', function () { } }); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'activateCmp' }, { path: '/b', component: 'oneCmp' } ]); compile('outer {
}'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(elt.text()).toBe('outer { hi }'); - $router.navigateByUrl('/b'); + $rootRouter.navigateByUrl('/b'); $rootScope.$digest(); expect(elt.text()).toBe('outer { hi }'); }); @@ -388,17 +388,17 @@ describe('Navigation lifecycle', function () { } }); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'activateCmp' }, { path: '/b', component: 'oneCmp' } ]); compile('outer {
}'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(elt.text()).toBe('outer { hi }'); - $router.navigateByUrl('/b'); + $rootRouter.navigateByUrl('/b'); $rootScope.$digest(); expect(elt.text()).toBe('outer { one }'); }); @@ -414,12 +414,12 @@ describe('Navigation lifecycle', function () { $routerOnActivate: spy }); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'activateCmp' } ]); compile('
'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(spy).toHaveBeenCalled(); @@ -433,15 +433,15 @@ describe('Navigation lifecycle', function () { $routerCanDeactivate: spy }); - $router.config([ + $rootRouter.config([ { path: '/user/:name', component: 'deactivateCmp' }, { path: '/post/:id', component: 'oneCmp' } ]); compile('
'); - $router.navigateByUrl('/user/brian'); + $rootRouter.navigateByUrl('/user/brian'); $rootScope.$digest(); - $router.navigateByUrl('/post/123'); + $rootRouter.navigateByUrl('/post/123'); $rootScope.$digest(); expect(spy).toHaveBeenCalledWith(instructionFor('oneCmp'), instructionFor('deactivateCmp')); diff --git a/modules/angular1_router/test/integration/navigation_spec.js b/modules/angular1_router/test/integration/navigation_spec.js index 4c2896c2ca..7213995943 100644 --- a/modules/angular1_router/test/integration/navigation_spec.js +++ b/modules/angular1_router/test/integration/navigation_spec.js @@ -5,7 +5,7 @@ describe('navigation', function () { var elt, $compile, $rootScope, - $router, + $rootRouter, $compileProvider; beforeEach(function () { @@ -15,10 +15,10 @@ describe('navigation', function () { $compileProvider = _$compileProvider_; }); - inject(function (_$compile_, _$rootScope_, _$router_) { + inject(function (_$compile_, _$rootScope_, _$rootRouter_) { $compile = _$compile_; $rootScope = _$rootScope_; - $router = _$router_; + $rootRouter = _$rootRouter_; }); registerDirective('userCmp', { @@ -52,11 +52,11 @@ describe('navigation', function () { it('should work in a simple case', function () { compile(''); - $router.config([ + $rootRouter.config([ { path: '/', component: 'oneCmp' } ]); - $router.navigateByUrl('/'); + $rootRouter.navigateByUrl('/'); $rootScope.$digest(); expect(elt.text()).toBe('one'); @@ -66,11 +66,11 @@ describe('navigation', function () { it('should work with components created by the `mod.component()` helper', function () { compile(''); - $router.config([ + $rootRouter.config([ { path: '/', component: 'threeCmp' } ]); - $router.navigateByUrl('/'); + $rootRouter.navigateByUrl('/'); $rootScope.$digest(); expect(elt.text()).toBe('three'); @@ -78,16 +78,16 @@ describe('navigation', function () { it('should navigate between components with different parameters', function () { - $router.config([ + $rootRouter.config([ { path: '/user/:name', component: 'userCmp' } ]); compile(''); - $router.navigateByUrl('/user/brian'); + $rootRouter.navigateByUrl('/user/brian'); $rootScope.$digest(); expect(elt.text()).toBe('hello brian'); - $router.navigateByUrl('/user/igor'); + $rootRouter.navigateByUrl('/user/igor'); $rootScope.$digest(); expect(elt.text()).toBe('hello igor'); }); @@ -106,17 +106,17 @@ describe('navigation', function () { controller: ParentController }); - $router.config([ + $rootRouter.config([ { path: '/parent/...', component: 'parentCmp' } ]); compile(''); - $router.navigateByUrl('/parent/user/brian'); + $rootRouter.navigateByUrl('/parent/user/brian'); $rootScope.$digest(); expect(instanceCount).toBe(1); expect(elt.text()).toBe('parent { hello brian }'); - $router.navigateByUrl('/parent/user/igor'); + $rootRouter.navigateByUrl('/parent/user/igor'); $rootScope.$digest(); expect(instanceCount).toBe(1); expect(elt.text()).toBe('parent { hello igor }'); @@ -131,12 +131,12 @@ describe('navigation', function () { ] }); - $router.config([ + $rootRouter.config([ { path: '/a/...', component: 'childCmp' } ]); compile('
outer {
}
'); - $router.navigateByUrl('/a/b'); + $rootRouter.navigateByUrl('/a/b'); $rootScope.$digest(); expect(elt.text()).toBe('outer { inner { one } }'); @@ -150,12 +150,12 @@ describe('navigation', function () { ] }); - $router.config([ + $rootRouter.config([ { path: '/...', component: 'childCmp' } ]); compile('
outer {
}
'); - $router.navigateByUrl('/b'); + $rootRouter.navigateByUrl('/b'); $rootScope.$digest(); expect(elt.text()).toBe('outer { inner { one } }'); @@ -171,26 +171,26 @@ describe('navigation', function () { { path: '/end', component: 'oneCmp' } ]}); - $router.config([ + $rootRouter.config([ { path: '/recur', component: 'recurCmp' }, { path: '/', component: 'oneCmp' } ]); compile('
root {
}
'); - $router.navigateByUrl('/recur/recur/end'); + $rootRouter.navigateByUrl('/recur/recur/end'); $rootScope.$digest(); expect(elt.text()).toBe('root { one }'); }); it('should change location path', inject(function ($location) { - $router.config([ + $rootRouter.config([ { path: '/user', component: 'userCmp' } ]); compile('
'); - $router.navigateByUrl('/user'); + $rootRouter.navigateByUrl('/user'); $rootScope.$digest(); expect($location.path()).toBe('/user'); @@ -198,13 +198,13 @@ describe('navigation', function () { it('should pass through query terms to the location', inject(function ($location) { - $router.config([ + $rootRouter.config([ { path: '/user', component: 'userCmp' } ]); compile('
'); - $router.navigateByUrl('/user?x=y'); + $rootRouter.navigateByUrl('/user?x=y'); $rootScope.$digest(); expect($location.path()).toBe('/user'); @@ -215,12 +215,12 @@ describe('navigation', function () { it('should change location to the canonical route', inject(function ($location) { compile('
'); - $router.config([ + $rootRouter.config([ { path: '/', redirectTo: ['/User'] }, { path: '/user', component: 'userCmp', name: 'User' } ]); - $router.navigateByUrl('/'); + $rootRouter.navigateByUrl('/'); $rootScope.$digest(); expect($location.path()).toBe('/user'); @@ -236,7 +236,7 @@ describe('navigation', function () { ] }); - $router.config([ + $rootRouter.config([ { path: '/old-parent/old-child', redirectTo: ['/NewParent', 'NewChild'] }, { path: '/old-parent/old-child-two', redirectTo: ['/NewParent', 'NewChildTwo'] }, { path: '/new-parent/...', component: 'childRouter', name: 'NewParent' } @@ -244,13 +244,13 @@ describe('navigation', function () { compile('
'); - $router.navigateByUrl('/old-parent/old-child'); + $rootRouter.navigateByUrl('/old-parent/old-child'); $rootScope.$digest(); expect($location.path()).toBe('/new-parent/new-child'); expect(elt.text()).toBe('inner { one }'); - $router.navigateByUrl('/old-parent/old-child-two'); + $rootRouter.navigateByUrl('/old-parent/old-child-two'); $rootScope.$digest(); expect($location.path()).toBe('/new-parent/new-child-two'); @@ -259,7 +259,7 @@ describe('navigation', function () { it('should navigate when the location path changes', inject(function ($location) { - $router.config([ + $rootRouter.config([ { path: '/one', component: 'oneCmp' } ]); compile('
'); @@ -272,7 +272,7 @@ describe('navigation', function () { it('should navigate when the location query changes', inject(function ($location) { - $router.config([ + $rootRouter.config([ { path: '/get/params', component: 'getParams' } ]); compile('
'); @@ -284,7 +284,7 @@ describe('navigation', function () { })); - it('should expose a "navigating" property on $router', inject(function ($q) { + it('should expose a "navigating" property on $rootRouter', inject(function ($q) { var defer; registerDirective('pendingActivate', { $canActivate: function () { @@ -292,17 +292,17 @@ describe('navigation', function () { return defer.promise; } }); - $router.config([ + $rootRouter.config([ { path: '/pending-activate', component: 'pendingActivate' } ]); compile('
'); - $router.navigateByUrl('/pending-activate'); + $rootRouter.navigateByUrl('/pending-activate'); $rootScope.$digest(); - expect($router.navigating).toBe(true); + expect($rootRouter.navigating).toBe(true); defer.resolve(); $rootScope.$digest(); - expect($router.navigating).toBe(false); + expect($rootRouter.navigating).toBe(false); })); function registerDirective(name, options) { diff --git a/modules/angular1_router/test/integration/router_spec.js b/modules/angular1_router/test/integration/router_spec.js index 7c8eb1150e..9ef4224545 100644 --- a/modules/angular1_router/test/integration/router_spec.js +++ b/modules/angular1_router/test/integration/router_spec.js @@ -5,7 +5,7 @@ describe('router', function () { var elt, $compile, $rootScope, - $router, + $rootRouter, $compileProvider; beforeEach(function () { @@ -18,10 +18,10 @@ describe('router', function () { $compileProvider = _$compileProvider_; }); - inject(function (_$compile_, _$rootScope_, _$router_) { + inject(function (_$compile_, _$rootScope_, _$rootRouter_) { $compile = _$compile_; $rootScope = _$rootScope_; - $router = _$router_; + $rootRouter = _$rootRouter_; }); }); diff --git a/modules/angular1_router/test/integration/shim_spec.js b/modules/angular1_router/test/integration/shim_spec.js index e2edffe552..31dec18b5c 100644 --- a/modules/angular1_router/test/integration/shim_spec.js +++ b/modules/angular1_router/test/integration/shim_spec.js @@ -5,7 +5,7 @@ describe('ngRoute shim', function () { var elt, $compile, $rootScope, - $router, + $rootRouter, $compileProvider, $routeProvider; @@ -18,10 +18,10 @@ describe('ngRoute shim', function () { $routeProvider = _$routeProvider_; }); - inject(function (_$compile_, _$rootScope_, _$router_) { + inject(function (_$compile_, _$rootScope_, _$rootRouter_) { $compile = _$compile_; $rootScope = _$rootScope_; - $router = _$router_; + $rootRouter = _$rootRouter_; }); }); @@ -36,7 +36,7 @@ describe('ngRoute shim', function () { compile(''); - $router.navigateByUrl('/'); + $rootRouter.navigateByUrl('/'); $rootScope.$digest(); expect(elt.text()).toBe('one'); @@ -55,7 +55,7 @@ describe('ngRoute shim', function () { compile('root {}'); - $router.navigateByUrl('/'); + $rootRouter.navigateByUrl('/'); $rootScope.$digest(); expect(elt.text()).toBe('root {one}'); })); @@ -76,7 +76,7 @@ describe('ngRoute shim', function () { compile(''); - $router.navigateByUrl('/'); + $rootRouter.navigateByUrl('/'); $rootScope.$digest(); expect(elt.text()).toBe('value: 42'); @@ -94,11 +94,11 @@ describe('ngRoute shim', function () { compile(''); - $router.navigateByUrl('/user/brian'); + $rootRouter.navigateByUrl('/user/brian'); $rootScope.$digest(); expect(elt.text()).toBe('hello brian'); - $router.navigateByUrl('/user/igor'); + $rootRouter.navigateByUrl('/user/igor'); $rootScope.$digest(); expect(elt.text()).toBe('hello igor'); }); @@ -115,7 +115,7 @@ describe('ngRoute shim', function () { compile(''); - $router.navigateByUrl('/home/foo/bar/123'); + $rootRouter.navigateByUrl('/home/foo/bar/123'); $rootScope.$digest(); expect(elt.text()).toBe('rest: foo/bar/123'); }); @@ -129,7 +129,7 @@ describe('ngRoute shim', function () { compile('root {}'); - $router.navigateByUrl('/home/test'); + $rootRouter.navigateByUrl('/home/test'); $rootScope.$digest(); expect(elt.text()).toBe('root {}'); expect(console.warn) @@ -150,7 +150,7 @@ describe('ngRoute shim', function () { compile('root {}'); - $router.navigateByUrl('/'); + $rootRouter.navigateByUrl('/'); $rootScope.$digest(); expect(elt.text()).toBe('root {welcome home!}'); expect($location.path()).toBe('/home'); @@ -169,7 +169,7 @@ describe('ngRoute shim', function () { compile('root {}'); - $router.navigateByUrl('/somewhere'); + $rootRouter.navigateByUrl('/somewhere'); $rootScope.$digest(); expect(elt.text()).toBe('root {welcome home!}'); expect($location.path()).toBe('/home'); diff --git a/modules/angular1_router/test/ng_link_spec.js b/modules/angular1_router/test/ng_link_spec.js index 95ff2efcb3..56b613fb6c 100644 --- a/modules/angular1_router/test/ng_link_spec.js +++ b/modules/angular1_router/test/ng_link_spec.js @@ -5,7 +5,7 @@ describe('ngLink', function () { var elt, $compile, $rootScope, - $router, + $rootRouter, $compileProvider; beforeEach(function () { @@ -15,10 +15,10 @@ describe('ngLink', function () { $compileProvider = _$compileProvider_; }); - inject(function (_$compile_, _$rootScope_, _$router_) { + inject(function (_$compile_, _$rootScope_, _$rootRouter_) { $compile = _$compile_; $rootScope = _$rootScope_; - $router = _$router_; + $rootRouter = _$rootRouter_; }); registerComponent('userCmp', '
hello {{userCmp.$routeParams.name}}
', function () {}); @@ -28,26 +28,26 @@ describe('ngLink', function () { it('should allow linking from the parent to the child', function () { - $router.config([ + $rootRouter.config([ { path: '/a', component: 'oneCmp' }, { path: '/b', component: 'twoCmp', name: 'Two' } ]); compile('link | outer {
}'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(elt.find('a').attr('href')).toBe('./b'); }); it('should allow linking from the child and the parent', function () { - $router.config([ + $rootRouter.config([ { path: '/a', component: 'oneCmp' }, { path: '/b', component: 'twoCmp', name: 'Two' } ]); compile('outer {
}'); - $router.navigateByUrl('/b'); + $rootRouter.navigateByUrl('/b'); $rootScope.$digest(); expect(elt.find('a').attr('href')).toBe('./b'); @@ -57,13 +57,13 @@ describe('ngLink', function () { it('should allow params in routerLink directive', function () { registerComponent('twoLinkCmp', '
{{twoLinkCmp.number}}
', function () {this.number = 'two'}); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'twoLinkCmp' }, { path: '/b/:param', component: 'twoCmp', name: 'Two' } ]); compile('
'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(elt.find('a').attr('href')).toBe('./b/lol'); @@ -72,13 +72,13 @@ describe('ngLink', function () { it('should update the href of links with bound params', function () { registerComponent('twoLinkCmp', '
{{twoLinkCmp.number}}
', function () {this.number = 'param'}); - $router.config([ + $rootRouter.config([ { path: '/a', component: 'twoLinkCmp' }, { path: '/b/:param', component: 'twoCmp', name: 'Two' } ]); compile('
'); - $router.navigateByUrl('/a'); + $rootRouter.navigateByUrl('/a'); $rootScope.$digest(); expect(elt.find('a').attr('href')).toBe('./b/param'); @@ -86,7 +86,7 @@ describe('ngLink', function () { it('should navigate on left-mouse click when a link url matches a route', function () { - $router.config([ + $rootRouter.config([ { path: '/', component: 'oneCmp' }, { path: '/two', component: 'twoCmp', name: 'Two'} ]); @@ -104,8 +104,8 @@ describe('ngLink', function () { }); - it('should not navigate on non-left mouse click when a link url matches a route', inject(function ($router) { - $router.config([ + it('should not navigate on non-left mouse click when a link url matches a route', inject(function ($rootRouter) { + $rootRouter.config([ { path: '/', component: 'oneCmp' }, { path: '/two', component: 'twoCmp', name: 'Two'} ]); @@ -122,7 +122,7 @@ describe('ngLink', function () { // See https://github.com/angular/router/issues/206 it('should not navigate a link without an href', function () { - $router.config([ + $rootRouter.config([ { path: '/', component: 'oneCmp' }, { path: '/two', component: 'twoCmp', name: 'Two'} ]); diff --git a/modules/angular1_router/test/util.es5.js b/modules/angular1_router/test/util.es5.js index 31568d74b2..9b58fa6c6c 100644 --- a/modules/angular1_router/test/util.es5.js +++ b/modules/angular1_router/test/util.es5.js @@ -22,7 +22,7 @@ function provideHelpers(fn, preInject) { var elt, $compile, $rootScope, - $router, + $rootRouter, $templateCache, $controllerProvider; @@ -32,10 +32,10 @@ function provideHelpers(fn, preInject) { $controllerProvider = _$controllerProvider_; }); - inject(function(_$compile_, _$rootScope_, _$router_, _$templateCache_) { + inject(function(_$compile_, _$rootScope_, _$rootRouter_, _$templateCache_) { $compile = _$compile_; $rootScope = _$rootScope_; - $router = _$router_; + $rootRouter = _$rootRouter_; $templateCache = _$templateCache_; }); @@ -72,7 +72,7 @@ function provideHelpers(fn, preInject) { fn({ registerComponent: registerComponent, - $router: $router, + $rootRouter: $rootRouter, put: put, compile: compile })