diff options
| author | Igor Minar | 2011-02-06 09:35:14 -0800 |
|---|---|---|
| committer | Igor Minar | 2011-02-06 09:35:14 -0800 |
| commit | ea9ca651d2dd40ec057a166c6f324ea4fb881428 (patch) | |
| tree | 2852c04856533e2dfa262997647d7d74f09412b5 | |
| parent | d6db4b174940782867d1cf42e1e0152046fe05c1 (diff) | |
| download | angular.js-ea9ca651d2dd40ec057a166c6f324ea4fb881428.tar.bz2 | |
fix how redirection is handled and tested
| -rw-r--r-- | src/angular-mocks.js | 2 | ||||
| -rw-r--r-- | src/services.js | 19 | ||||
| -rw-r--r-- | test/servicesSpec.js | 7 |
3 files changed, 14 insertions, 14 deletions
diff --git a/src/angular-mocks.js b/src/angular-mocks.js index 1093b061..762148fd 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -91,8 +91,8 @@ function MockBrowser() { self.pollFns.push( function() { if (self.lastUrl != self.url) { - listener(); self.lastUrl = self.url; + listener(); } } ); diff --git a/src/services.js b/src/services.js index eb0a473f..5c91aa59 100644 --- a/src/services.js +++ b/src/services.js @@ -693,7 +693,7 @@ function switchRouteMatcher(on, when, dstName) { </doc:scenario> </doc:example> */ -angularServiceInject('$route', function(location) { +angularServiceInject('$route', function(location, $updateView) { var routes = {}, onChange = [], matcher = switchRouteMatcher, @@ -818,15 +818,16 @@ angularServiceInject('$route', function(location) { if(routeParams) { if (routeParams.redirectTo) { - location.updateHash(routeParams.redirectTo); //let $browser trigger next route change + location.updateHash(routeParams.redirectTo); + $updateView(); //TODO this is to work around the $location<=>$browser issues return; - } else { - childScope = createScope(parentScope); - $route.current = extend({}, routeParams, { - scope: childScope, - params: extend({}, location.hashSearch, pathParams) - }); } + + childScope = createScope(parentScope); + $route.current = extend({}, routeParams, { + scope: childScope, + params: extend({}, location.hashSearch, pathParams) + }); } //fire onChange callbacks @@ -840,7 +841,7 @@ angularServiceInject('$route', function(location) { this.$watch(function(){return dirty + location.hash;}, updateRoute); return $route; -}, ['$location']); +}, ['$location', '$updateView']); /** * @workInProgress diff --git a/test/servicesSpec.js b/test/servicesSpec.js index e3437dc2..0876f986 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -486,7 +486,7 @@ describe("service", function(){ expect(onChangeSpy).not.toHaveBeenCalled(); scope.$eval(); //triggers initial route change - match the redirect route - $browser.poll(); //triger route change - match the route we redirected to + $browser.defer.flush(); //triger route change - match the route we redirected to expect($location.hash).toBe('/foo'); expect($route.current.template).toBe('foo.html'); @@ -495,8 +495,7 @@ describe("service", function(){ onChangeSpy.reset(); $location.updateHash(''); scope.$eval(); //match the redirect route + update $browser - $browser.poll(); //match the route we redirected to - + $browser.defer.flush(); //match the route we redirected to expect($location.hash).toBe('/foo'); expect($route.current.template).toBe('foo.html'); @@ -505,7 +504,7 @@ describe("service", function(){ onChangeSpy.reset(); $location.updateHash('/baz'); scope.$eval(); //match the redirect route + update $browser - $browser.poll(); //match the route we redirected to + $browser.defer.flush(); //match the route we redirected to expect($location.hash).toBe('/bar'); expect($route.current.template).toBe('bar.html'); |
