I had a similar problem and used the injector service. (I don't know if this is the easiest solution, but it worked for me :))
Since $ location cannot be relied upon during tests, I prepared my own layout. First, you need to create a factory method. (Or service or provider, if you want - see https://gist.github.com/Mithrandir0x/3639232 for comparison):
function locationFactory(_host) { return function () { return { host: function () { return _host; } }; }; }
Then , before you create your "Env" , the feed injector with this layout $ location:
module(function ($provide) { $provide.factory('$location', locationFactory('http://staging-site.com')); });
Now, every time your access to $ location is in your code, your layout is introduced, so it returns everything you need. More on the $ extra method can be found in angular docs
Hope this helps you in the future.
Update: I see one place where you may have been wrong (or at least wrong in my decision). It looks like you are initiating the "Env" module (which, I think, calculates the data immediately), and only after that you change $ location - it may be too late.
Majki source share