I am new to AngularJS testing with Jasmine.
I have a service named pageService which relies on another services named fileLoader.
Within my page service I have the following code:
service.getPageInformation = function (pageName){
var defer = $q.defer();
fileLoader.getFile("pageInformation")
.then(function (res) {
for(var i = 0 ; i < res.length ; i++){
if(res[i].name == pageName)
defer.resolve(res[i]);
}
defer.reject("No Page found");
;
}, function (err) {
defer.reject(err);
});
return defer.promise;
};
Which tries to get a file and does some logic on retrieval.
The get file method is shown below.
fileLoader.getFile = function(name){
var defer = $q.defer();
$http.get("data/" + name + ".json")
.success(function(res){
defer.resolve(res);
})
.error(function(err,status){
defer.reject(err);
});
return defer.promise;
}
To unit test the page service I have tried spying, mocking, decorating the file loader and I just can't get a simple test to work.
Can someone help me create a basic test?
Thanks
Aucun commentaire:
Enregistrer un commentaire