diff options
| author | Misko Hevery | 2012-05-22 16:45:56 -0700 |
|---|---|---|
| committer | Misko Hevery | 2012-06-02 15:44:58 -0700 |
| commit | 92a2e1807657c69e1372106b0727675a30f4cbd7 (patch) | |
| tree | f236f146b44c4a03cfc04e48e6dba878c74c6153 /test/ng/routeSpec.js | |
| parent | 8aa18f0ad036fd4f2dc26f54d80754c70232b4f7 (diff) | |
| download | angular.js-92a2e1807657c69e1372106b0727675a30f4cbd7.tar.bz2 | |
feat($location): add $locatonChange[begin|completed] event
This allows location change cancelation
Diffstat (limited to 'test/ng/routeSpec.js')
| -rw-r--r-- | test/ng/routeSpec.js | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/test/ng/routeSpec.js b/test/ng/routeSpec.js index 8c5f93f9..31d932f7 100644 --- a/test/ng/routeSpec.js +++ b/test/ng/routeSpec.js @@ -60,6 +60,28 @@ describe('$route', function() { }); + it('should not change route when location is canceled', function() { + module(function($routeProvider) { + $routeProvider.when('/somePath', {template: 'some path'}); + }); + inject(function($route, $location, $rootScope, $log) { + $rootScope.$on('$locationChangeStart', function(event) { + $log.info('$locationChangeStart'); + event.preventDefault(); + }); + + $rootScope.$on('$beforeRouteChange', function(event) { + throw new Error('Should not get here'); + }); + + $location.path('/somePath'); + $rootScope.$digest(); + + expect($log.info.logs.shift()).toEqual(['$locationChangeStart']); + }); + }); + + it('should match a route that contains special chars in the path', function() { module(function($routeProvider) { $routeProvider.when('/$test.23/foo(bar)/:baz', {templateUrl: 'test.html'}); @@ -540,8 +562,11 @@ describe('$route', function() { }); inject(function($route, $location, $rootScope) { var replace; - $rootScope.$watch(function() { - if (isUndefined(replace)) replace = $location.$$replace; + + $rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) { + if (oldUrl == 'http://server/#/foo/id3/eId') { + replace = $location.$$replace; + } }); $location.path('/foo/id3/eId'); |
