Promise from service is not getting resolved in jasmine
<p>I have a function in service which returns a promise.
When I mock $http post, the promise always goes to rejected state</p>

<pre><code>beforeEach(inject(function (testService, constantService, $http, $injector, $rootScope, $q) {
        $httpBackend = $injector.get("$httpBackend");
        _testService_ = testService;
    _constantService_ = constantService;
        _$rootScope_ = $rootScope;
        $scope = $rootScope.$new();
        deferred = $q.defer();
})); 


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

it('should post user form data and get an object back', function() {
        var response;
        var formData = {};

        $httpBackend.when("POST", "http://localhost/postform").respond({
            data: {
                responseStatus:true,
                reportPath :"somepath"
            }
        });

        var promise = _testService_.postData("http://localhost" + _constantService_.getWebService('link.dataParameterURL.POST'), formData);

        promise.then(function(res) {
            response = res;
        }, function(errorData){
            console.log(errorData)
        });

        _$rootScope_.$apply();

        $httpBackend.flush();

        expect(response).toBeDefined();
    });
</code></pre>

<p><strong>Response is always undefined.</strong></p>

<p>If I use the below code the promise gets resolved.</p>

<pre><code>var s = $http.post("http://localhost" + constantService.getWebService('link.dataParameterURL.POST'), formData).success(function (res) {
            if(res!=undefined &amp;&amp; res.responseStatus!=undefined &amp;&amp; res.responseStatus === true) {
                d.resolve(res);
            }else{
                d.reject();
            }
        }).error(function (e,status) {
            d.reject(e)
        });

        s.then(function(res) {
            response = res;
        }, function(errorData){
            console.log(errorData)
        });
</code></pre>

<p>TestService.js</p>

<pre><code> this.postData = function(url, dataToPOST) {
            var d = $q.defer();
            $http.post(url, dataToPOST).success(function (res) {
                if(res!=undefined &amp;&amp; res.responseStatus!=undefined &amp;&amp; res.responseStatus === true) {
                    d.resolve(res);
                }else{
                    d.reject();
                }
            }).error(function (e,status) {
                d.reject(e)
            });
            return d.promise;
        };
</code></pre>