diff options
| author | Igor Minar | 2012-04-03 15:28:09 -0700 |
|---|---|---|
| committer | Igor Minar | 2012-04-04 16:10:44 -0700 |
| commit | 15ecc6f3668885ebc5c7130dd34e00059ddf79ae (patch) | |
| tree | ab037fbdf3df20f53e96169925367536de736ce7 /test | |
| parent | 53b2254ea70019937463d8e079e1991b3d3d1d8b (diff) | |
| download | angular.js-15ecc6f3668885ebc5c7130dd34e00059ddf79ae.tar.bz2 | |
feat($route): allow chaining of whens and otherwise
Previously one had to write:
$routeProvider.when('/foo', {...});
$routeProvider.when('/bar', {...});
$routeProvider.otherwise({...});
After this change it's just:
$routeProvider.
when('/foo', {...}).
when('/bar', {...}).
otherwise({...});
Breaks #when which used to return the route definition object but now
returns self. Returning the route definition object is not very useful
so its likely that nobody ever used it.
Diffstat (limited to 'test')
| -rw-r--r-- | test/ng/routeParamsSpec.js | 4 | ||||
| -rw-r--r-- | test/ng/routeSpec.js | 20 |
2 files changed, 21 insertions, 3 deletions
diff --git a/test/ng/routeParamsSpec.js b/test/ng/routeParamsSpec.js index d1b2ecb1..e3aac1a2 100644 --- a/test/ng/routeParamsSpec.js +++ b/test/ng/routeParamsSpec.js @@ -3,8 +3,8 @@ describe('$routeParams', function() { it('should publish the params into a service', function() { module(function($routeProvider) { - $routeProvider.when('/foo'); - $routeProvider.when('/bar/:barId'); + $routeProvider.when('/foo', {}); + $routeProvider.when('/bar/:barId', {}); }); inject(function($rootScope, $route, $location, $routeParams) { diff --git a/test/ng/routeSpec.js b/test/ng/routeSpec.js index 88e54b9a..b66cbb8e 100644 --- a/test/ng/routeSpec.js +++ b/test/ng/routeSpec.js @@ -10,7 +10,7 @@ describe('$route', function() { module(function($routeProvider) { $routeProvider.when('/Book/:book/Chapter/:chapter', {controller: noop, template: 'Chapter.html'}); - $routeProvider.when('/Blank'); + $routeProvider.when('/Blank', {}); }); inject(function($route, $location, $rootScope) { $rootScope.$on('$beforeRouteChange', function(event, next, current) { @@ -147,6 +147,24 @@ describe('$route', function() { }); + it('should chain whens and otherwise', function() { + module(function($routeProvider){ + $routeProvider.when('/foo', {template: 'foo.html'}). + otherwise({template: 'bar.html'}). + when('/baz', {template: 'baz.html'}); + }); + + inject(function($route, $location, $rootScope) { + $rootScope.$digest(); + expect($route.current.template).toBe('bar.html'); + + $location.url('/baz'); + $rootScope.$digest(); + expect($route.current.template).toBe('baz.html'); + }); + }); + + it('should not fire $after/beforeRouteChange during bootstrap (if no route)', function() { var routeChangeSpy = jasmine.createSpy('route change'); |
