mercredi 27 janvier 2016

How to do unit testing using jasmine on that factory?

I try to make a unit test on that code that consists of factory that take behavior Name and contracts an http request in a closure ?

var app = angular.module("behaviour",[]);

var behaviour = app.factory('Behaviours',['http',function(http){

var BehavioursJson = $http.get('data.json');
return {
    getBehaviour : function(behaviourName) {

        if (BehavioursJson[behaviourName]) {

            var behaviour = BehavioursJson[behaviourName];
            return function (behaviourData, callback) {
                var keys = Object.allKeys(behaviourData);
                var headers = {};
                var data = {};
                var url = behaviour.path;

                // some process to fill headers and data objects

                $http({
                    method: behaviour.method,
                    url: url,
                    data:  data,
                    headers: headers
                }).then(function successCallback(response) {
                    callback(response,null);
                },function errorCallback(error) {
                    callback(null,error);
                });

            }
        };
    return null;
    }
}

}]);

Note: using jasmine

Aucun commentaire:

Enregistrer un commentaire