title: How do I mock $location.host() in angularjs tests?
body: <p>I have created an <code>Env</code> service which wraps up environment information, and I'm currently using <code>$location.host()</code> to determine what environment I'm in. How do I mock that in my tests?</p>
  
  <p>I've read <a href="https://groups.google.com/forum/?fromgroups#!topic/angular/F0jFWC4G9hI" rel="noreferrer">https://groups.google.com/forum/?fromgroups#!topic/angular/F0jFWC4G9hI</a>, but it doesn't seem to work, for example:</p>
  
  <pre><code>describe("Env (environment) service", function() {
  
    var Env;
  
    beforeEach(module('App'));
  
    beforeEach(inject(
      ['Env', function(e) {
        Env = e;
      }]
    ));
  
    describe("for staging", function() {
      beforeEach(inject(function($location, $rootScope) {
        $location.host("http://staging-site.com");
        $rootScope.$apply();
      }));
  
      it("returns envrionment as staging", function() {
        expect(Env.environment).toEqual("staging");
      });
  
      it("returns .isStaging() as true", function() {
        expect(Env.isStaging()).toBeTruthy();
      });
    });
  });
  </code></pre>
  
  <p>I've also tried the <code>$browser</code> variant, but that doesn't work either. Any ideas?</p>