컨트롤러에 다음 코드가 있으며이 파트에 재스민 테스트 케이스를 쓰고 싶습니다. 나는 하나를 작성했는데, 그 던지는 오류를 다음 형식 오류 : 개체 [객체 배열]있는 방법 '다음'컨트롤러에 재스민 테스트 케이스를 쓸 수 없습니다.
컨트롤러 코드 :
$scope.doGetList = function() {
var queryString = {......sending some query parameters};
searchResource.getList(queryString).then(
function (data) {
$scope.sugesstions = data;
}
);
};
재스민 테스트 케이스 ::
it("should return provided list", angular.mock.inject(function($rootScope, $controller) {
var scope = $rootScope.$new();
var searchResource = {
getList: function() {
return ['suggestions1', 'suggestions2', 'suggestions3'];
}
};
$controller(
headerController,
{
$scope: scope,
cartsService: null,
currentUser: null,
searchResource: searchResource
}
);
expect(scope.sugesstions).toBeDefined();
expect(scope.sugesstions.length).toBe(0);
//this method will call mock method instead of actual server call
scope.doGetAutocomplete();
expect(scope.sugesstions.length).toBe(3);
expect(scope.sugesstions[0]).toEqual('suggestions1');
expect(scope.sugesstions[1]).toEqual('suggestions2');
expect(scope.sugesstions[2]).toEqual('suggestions3');
}));
이 없습니다
어떻게 작성해야합니까?
... 어떤 제안? – IfOnly