title: AngularJS : mock http service (Using $httpBackend) to respond with some data to the success method of Promise API
body: <p>I tried to interpret simpler version of my question.<br>
  1)I m writing Unit tests forcontroller(myController) method(subtract).<br>
  2)mocking http using httpbackend i want to return a response of 200 to success function of http in subtract method to down its value in the success function of any dummy DELETE url(which is always successful outside test environment).<br>
  3)But i see expect(scope.testvalue) to be 5 only.
   Any help is appreciated.</p>
  
  <pre><code>'use strict';
  describe('MyController UNIT TEST specs ', function () {    
  var scope, http, location, ctrl, httpBackend;
  beforeEach(module('myApp', 'ui.router')); 
  
  beforeEach(inject(function ($rootScope, $http, $controller, $httpBackend) {
      scope = $rootScope.$new();
      http = $http;
      httpBackend = $httpBackend;
      ctrl = $controller('myController', { $scope: scope, $http: http});
      httpBackend.when('DELETE', 'url').respond(200, 'fsdf');
  }));
  
  afterEach(function () {
      httpBackend.verifyNoOutstandingExpectation();
      httpBackend.verifyNoOutstandingRequest();
  });    
  
  it('test 1 : Subtract 1 from a value enter code here` using subtract method in myController', function () {
      httpBackend.when('DELETE', 'url').respond(200);
      var testvalue = 5;
      scope.subtract(testvalue);
      expect(testvalue).toBe(4);
  });
  });
  angular.module("myApp").controller("myController", function ($scope, $http) {    
      $scope.subtract = function (testValue) {    
          $http({
              method: 'DELETE',
              url: 'url'
          }).then(function (data) { //success    
              //irrespective of data subtract 1 here     
              testValue - 1 = 4;    
          }, function (errResult) { //fail
              console.log(errResult);
          });
      }
  })
  </code></pre>
  
  <p>Error i see is (expected)
  <strong>Error: Expected false to be true.</strong></p>