dimanche 26 juillet 2015

How to create unit-testing for $http promise in AngularJS

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) {
                   def.resolve(data);
               })
               .error(function (error) {
                   def.reject(error);
                });
         return def.promise;
    };
}]);

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.

Aucun commentaire:

Enregistrer un commentaire