title: Cannot read property '0' of undefined (only on unit test)
body: <p>I don't understand why I'm getting the following error :</p>
  
  <blockquote>
    <p>Chrome 43.0.2357 (Windows 7 0.0.0) Requests controller test should
    fill properties from result from xhr requests FAILED
            TypeError: Cannot read property '0' of undefined
                at getLastStatus (C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/app/tools.js:68:43)
                at C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/app/requests/requests.js:238:42
                at processQueue (C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/bower_components/angular/angular.js:14792:28)
                at C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/bower_components/angular/angular.js:14808:27
                at Scope.$eval (C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/bower_components/angular/angular.js:16052:28)
                at Scope.$digest (C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/bower_components/angular/angular.js:15870:31)
                at Scope.$apply (C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/bower_components/angular/angular.js:16160:24)
                at done (C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/bower_components/angular/angular.js:10589:47)
                at handleResponse (C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/bower_components/angular-mocks/angular-mocks.js:1194:9)
                at Function.$httpBackend.flush (C:/Users/aazor102115/Desktop/Dev/Balrog/Front/Balrog-UI/bower_components/angular-mocks/angular-mocks.js:1553:26)</p>
  </blockquote>
  
  <p>This error is showed only on the karma logs.</p>
  
  <p>But it shouldn't be undefined because of a loop condition.</p>
  
  <p>In the tools.js file :</p>
  
  <pre><code>function getLastStatus(statuses) {
    var lastStatusDate = Date.parse(statuses[0].date); // this is the line pointed in the error
    var lastIndex = 0;
  
    for (var i = 0; statuses[i]; i++) {
      var currentStatusDate = Date.parse(statuses[i].date);
  
      if (currentStatusDate &gt; lastStatusDate) {
        lastStatusDate = currentStatusDate;
        lastIndex = i;
      }
    }
    return statuses[lastIndex];
  }
  </code></pre>
  
  <p>In the requests.js file :</p>
  
  <pre><code>Requests.query().$promise.then(function(result) {
        controllerScope.requestsList = [];
        for (var i = 0; result[i]; i++) {
          var currentRequest = {
            id: result[i]["id"],
            projectTitle: result[i]["project"].title,
            status: getLastStatus(result[i]["statuses"]).status, // this is the line pointed in the error
            description: result[i]["description"],
            regions: regionsIdToName(controllerScope.regionsList, result[i]["project"].regions),
            requestDate: moment(result[i]["request_date"]).format("MM-DD-YYYY"),
            developers: result[i]["developers"],
            statusDate: moment(getLastStatus(result[i]["statuses"]).date).format("MM-DD-YYYY")
          };
          controllerScope.requestsList.push(currentRequest);
        }
      });
  </code></pre>
  
  <p><strong>EDIT :</strong> When adding <code>console.log(statuses);</code> at the first ine of the <code>getLastStatus(statuses)</code> function :</p>
  
  <p>An array of object is displayed on the browser console, like it should.</p>
  
  <p>But undefined is displayed on the Karma console. So I don't get what is causing it.</p>