var app= angular.module('app', []);
below is my factory method that will get the data from the sample.json
app.factory('factoryGetJSONFile', function($http) {
return {
getMyData: function(done) {
$http.get('mock/sample.json')
.success(function(data) {
done(data);
})
.error(function(error) {
alert('An error occured whilst trying to retrieve your data');
});
}
}
});
below is my controller. I can able to access the service data in my controller
app.controller('homeController', ['$scope', 'factoryGetJSONFile', function ($scope, factoryGetJSONFile) {
factoryGetJSONFile.getMyData(function (data) {
$scope.name = data.projectDetails.name;
$scope.duration = data.projectDetails.duration;
console.log($scope.name+ " and duration is " + $scope.duration);
});
}]);
Below is my sample.json
{
"status": 200,
"projectDetails": {
"name": "Project Name",
"duration": "4 Months",
"business_place": "Dummy address"
}
}
How to write the unit test cases for the above get service. I would like to test projectDetails.name in my test cases.
Aucun commentaire:
Enregistrer un commentaire