我的控制器中有以下代碼,我想爲此部分編寫Jasmine測試用例。 我試着寫一個,但下面的錯誤及其投擲 類型錯誤:[對象對象數組]有沒有方法「然後」無法在ANgularJS中爲Controller編寫Jasmine測試用例
控制器代碼::
$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