getCheckoutItems: function() {
var defer = $q.defer();
var response = {
result: true,
data: '',
err: ''
};
if (!angular.isUndefined(productListSample)) {
response.data = productListSample;
defer.resolve(response);
} else {
response.result = false;
response.err = 'error';
defer.reject(response);
}
return defer.promise;
}
$scope.cart = {
items: [],
phoneNo: ''
};
$scope.getCheckoutItems = function() {
CartService.getCheckoutItems().then(function(result) {
$scope.cart.items = result.data;
}, function(err) {
});
};
it('get checkout items', inject(function($controller) {
$controller('Ctrl', {
$scope: scope
});
scope.getCheckoutItems();
console.log(scope.cart);
}));
I do not receive items in the karma test. the controller calls the service to receive data in async. this process is handled by an angular promise. but the problem is with recording the test case>, because the controller function returns before receiving data from the> service. how can i solve this problem?
source
share