title: Simulating an Empty Array Response from an HTTP Post Request using Karma
body: <p>I am using Karma to test my MEAN application, and am having difficulty returning an empty array from the $httpBackend 'expectPOST' method in AngularJS (ng-mock).</p>
  
  <p>Here is the service method I am testing:</p>
  
  <pre><code>  this.getIds = function(path, callback) {
      // console.log('Sending request to get IDs to the path: ' + path);
      $http.post('/dropbox/getIds', {path: path} ).success(function(items) {
        if(items.error !== undefined) {
          console.log(items.error);
          callback('Error with Dropbox API files list request'); // Do not alter string
          return;
        }
        var empty = (items.length === 0) ? true : false;
        callback(items, empty);
      }).error(function(err) {
        console.log(err);
        callback('Error making ID request');
      });
    };
  </code></pre>
  
  <p>And here is the unit test code snippet:</p>
  
  <pre><code>it('should request Dropbox file IDs at a give path - no errors but empty response', function() {
    $httpBackend.expectPOST("/dropbox/getIds").respond({ data: [] });
    dropboxService.getIds('path', function(items, empty) {
      expect(items).to.deep.equal({data: []});
      expect(empty).to.deep.equal(true);
    });
  });
  </code></pre>
  
  <p>The 'empty' variable should be true in this test as the HTTP POST response is an empty 'data' array, however the test fails as the 'empty' variable is actually false.</p>
  
  <p>Can someone show me what I have done wrong, either in the test code or perhaps the service method itself?</p>