2016-03-16 43 views
0

需要幫助測試控制器中的以下功能。控制器內的測試工廠顯示錯誤不是功能

getEmployeeList是在控制器中的自我調用函數加載數據在UI當控制器的負載,它是依賴於一個工廠,寫下面的代碼在控制器中的所有電流試驗與下面的錯誤而失敗 後「employeeService.employeeList不是一個函數

$scope.getEmployeeList = function() { 

         employeeService.employeeList().then(function (result) { 
          angular.forEach(result.results, function (item) { 
           $scope.employees.push({eId:item.id,eName:item.name}); 
          });        
         }); 
        }; 

$scope.getEmployeeList(); 

工廠裏面是一個簡單的$ http.get

define([], function(){ 
    "use strict"; 
    var emplABC = function($http, $window, $q, $log, constants){ 

     var defered = $q.defer(); 

     var employeeList = function() { 

       $http.get(constants.employeeApi, {withCredentials: true}) 
        .success(function (data) { 
         defered.resolve(data); 
        }).error(function (ex) { 
        $log.error("abc err", { 
         workFlow: 'employee List', 
         message: 'An unexpected error ist of employees:' + ex 
        }); 
       }); 
       return defered.promise; 
      }; 


     return { 
      employeeList : employeeList 
     }; 
    } ; 

    emplABC.$inject = ['$http','$window', '$q', '$log']; 

    return emplABC; 
}); 

請提出了一些例子...

+0

可你如何你的工廠代碼? –

+0

用工廠方法編輯了問題。 – user804401

+0

'enterpriseList'如何成爲工廠的'employeeList'方法(假設這就是你實際擁有的)? – Phil

回答

0

嘗試刪除var和使用,如:

EmployeeList的=函數(){