I have problems to test services of the app because I don't know how to do it.
In google search results I've found many tutorials and examples but nothing was useful for my purpose.
Also, I don't know when to use the $httpBackend and why I need to define a fake service?!
However my intention is to test the services whether they're return a response or not as well as you define an item and make a GET request to see if the value exists and so on.
But the main issue is to understand how can I define a unit test for services in my examples.
To have a better imagine, I put the code in this post:
Firstly testing the
CRUDService:
angular.module('testApp')
.factory('CrudService', ['ResService',
function (ResService) {
var service = {
getAllCompanies: getAllCompanies,
getAllGroups: getAllGroups
};
return service;
function getAllCompanies() {
return ResService.company.query();
}
function getAllGroups() {
return ResService.group.query();
}
}]);
Following the Service who communicates with the backend:
ResService:
angular.module('testApp')
.factory('ResService', ['$resource', 'baseUrl',
function ($resource, baseUrl) {
return {
company: $resource(baseUrl + '/api/company/:Id/:code', {
Id: '@Id',
code: '@code'
}, {
'update': {
method: 'PUT'
}
}),
group: $resource(baseUrl + '/api/group/:Id', {
Id: '@Id'
}, {})
...
Do anyone have an idea? I've tried
this example to integrate in my test but it was not the correct way..