I have a service with a function to use $http with promise. And i want create a unit-testing with jasmine.
account.service('AccountService', ['$q', '$http', function ($q, $http) {
this.getServerDataForUrl = function (url) {
var def = $q.defer();
$http.get(url)
.success(function (data) {
if (data) {
def.resolve(data);
} else {
def.reject();
}
})
.error(function (error) {
if (data) {
def.resolve(data);
} else {
def.resolve();
}
});
return def.promise;
};
}]);
UPDATE: Change something code when callback.
I've search about it but it not give me exactly function like this. Anyone give me some example to create unit-testing about it. I think this function is simple. Thanks.