jasmine error $httpBackend Unexpected request without domain
<p>My jasmine test for $httpBackend won't work unless I add the domain name, i.e. <a href="http://localhost:9808/" rel="nofollow noreferrer">http://localhost:9808/</a> </p>

<p>Since this test is used in several different environments I cannot use <a href="http://localhost:9808/" rel="nofollow noreferrer">http://localhost:9808/</a> </p>

<p>Without the domain I get this error:</p>

<p>Uncaught Error: Unexpected request: GET <a href="http://localhost:9808/api/mymethod" rel="nofollow noreferrer">http://localhost:9808/api/mymethod</a>
No more request expected</p>

<pre><code>    describe('test my service', function () {
        'use strict';

        var $httpBackend,
          myService;

        beforeEach(inject(function (_$injector_, _$httpBackend_) {
            var $injector = _$injector_;
            $httpBackend = _$httpBackend_;

            myService = $injector.get('myService');

            // this works
            //$httpBackend.whenGET('http://localhost:9808/api/mymethod').respond(200, mockData);

            // this throws error
            $httpBackend.whenGET('/api/mymethod').respond(200, mockData);
        }));

    afterEach(function () {
            $httpBackend.verifyNoOutstandingExpectation();
            $httpBackend.verifyNoOutstandingRequest();
        }); 

        it('check service exists and has methods', function () {
            expect(myService).toBeDefined();
            expect(myService.somemethod).toBeDefined();

        $httpBackend.flush();
    });
}); 
</code></pre>

<p>I even tried adding these lines to the beforeEach</p>

<p>// this also throws error</p>

<p>$httpBackend.when('GET', '/api/mymethod').respond(200, mockData);</p>

<p>// even adding expect still throws the error in the beforeEach
$httpBackend.expectGET('/api/mymethod');</p>

<p>Any ideas or suggestions on how to get this to work without using the domain?</p>

<p>Here is the service code that actually makes the request:</p>

<pre><code>(function(app) {

    'use strict';
    function MyService(apiService) {
        var returnDataObject = [];

        apiService.getAll().then(function(result) {
            returnDataObject = result.data;
        });

        this.myMethod = function() {
            if(returnDataObject) {
             return returnDataObject;
            }
            else {
            return null;
            }
        };

    }

    app.service('MyService', MyService);
    MyService.$inject = ['APIService'];

})(angular.module('app.mymodule'));
</code></pre>