Skip to content

Commit 938ea8a

Browse files
test($location): should not get caught in infinite digest when replacing empty path with slash
1 parent 462f444 commit 938ea8a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/ng/locationSpec.js

+43
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,49 @@ describe('$location', function() {
996996
}
997997
);
998998
});
999+
1000+
1001+
function mockUpBrowser(options) {
1002+
module(function($windowProvider, $browserProvider) {
1003+
$windowProvider.$get = function() {
1004+
var win = {};
1005+
angular.extend(win, window);
1006+
win.addEventListener = angular.noop;
1007+
win.removeEventListener = angular.noop;
1008+
win.location = {
1009+
href: options.initialUrl,
1010+
replace: function(val) {
1011+
win.location.href = val;
1012+
}
1013+
};
1014+
return win;
1015+
};
1016+
$browserProvider.$get = function($document, $window, $log, $sniffer) {
1017+
/* global Browser: false */
1018+
var b = new Browser($window, $document, $log, $sniffer);
1019+
b.baseHref = function() {
1020+
return options.baseHref;
1021+
};
1022+
return b;
1023+
};
1024+
});
1025+
}
1026+
1027+
1028+
it('should not get caught in infinite digest when replacing empty path with slash', function() {
1029+
initService({html5Mode:true,supportHistory:false});
1030+
mockUpBrowser({initialUrl:'http://server/base', baseHref:'/base/'});
1031+
inject(
1032+
function($browser, $location, $rootScope, $window) {
1033+
$rootScope.$on('$locationChangeSuccess', function() {
1034+
if ($location.path() !== '/') {
1035+
$location.path('/').replace();
1036+
}
1037+
});
1038+
$rootScope.$digest();
1039+
}
1040+
);
1041+
});
9991042
});
10001043

10011044

0 commit comments

Comments
 (0)