I'm currently using the Ionic framework to develop custom applications. Right now, I'm working on writing Unit tests for the factory datastoreServices
, which has dependencies on DomainService
and $http
. I'm struggling with implementing Jasmine Unit tests and could use some guidance.
Here are my factory functions:
app.factory("datastoreServices", ["$http", function($http) {
return {
getData: function(data, DomainService) {
return $http.post(DomainService.host + 'factor', data);
}
};
}]);
app.factory('DomainService', function() { //here
if (ionic.Platform.isAndroid()) {
return {
host: 'http://10.0.2.2:7001/'
}
}
return {
host: 'http://localhost:7001/'
}
})
Below is my unit test skeleton. With two dependencies, I'm unsure how to proceed. This is what I have so far in my unit test file:
describe(
'datastoreServices',
function() {
beforeEach(module('Myapp'));
describe('getData'),
function() {
it("Should return correct values", inject(function(datastoreServices, DomainService, $httpBackend) {
expect(datastoreServices.getData(httpBackend.. /***something here!**/ )
.toEqual("2.2");
}))
}
I have limited knowledge on mocking and testing. Can someone assist me in testing the factory datastoreServices
? The following aspects need to be tested:
- Is the Http post making the correct calls?
- Is the function returning the correct promise?
Here is a similar app scenario in plnkr.
I hope I'm not asking too much. Thank you in advance.