A long time since this question was asked, but the following approach should be cleaner:
By changing the original function to use Angular's $window service instead of the browser window object, it is possible to write a test that does not require modifying production code or take any runtime parameters into account. This of course requires that $window is a dependency for the controller where the function is found.
Using angular-mocks/ngMock, something like:
var fakeWindow = {
location: {
href: ''
}
}
// instantiate controller with mock window
beforeEach(inject(function($controller) {
$controller('YourCtrlName', {
$window: fakeWindow
});
}));
should allow the test to pass, assuming that the controller doesn't need $window for anything else.