mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix how redirection is handled and tested
This commit is contained in:
parent
d6db4b1749
commit
ea9ca651d2
3 changed files with 14 additions and 14 deletions
2
src/angular-mocks.js
vendored
2
src/angular-mocks.js
vendored
|
|
@ -91,8 +91,8 @@ function MockBrowser() {
|
|||
self.pollFns.push(
|
||||
function() {
|
||||
if (self.lastUrl != self.url) {
|
||||
listener();
|
||||
self.lastUrl = self.url;
|
||||
listener();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue