I have below factory where there is a dependency on private function. The private function is inside $http.get(url).success
define(['underscore'], function (_) {
"use strict";
function empConfigFactory($http, $q, $log, configManager, empConfig) {
var empSal = null;
//how do i test the below method.
function calculateEmpSal() {
var deferred = $q.defer();
emp = empConfig;
if (emp.designation === "Director") {
empSal.Salary = "soem value";
}
else if (emp.designation === "CoDirector") {
empSal.Salary = "soem value";
}
deferred.resolve(empSal);
return deferred.promise;
}
return {
"get": function () {
var url = "http://someUrl";
var deferred = $q.defer();
$http.get(url).success(function (data) {
empSal = data;
if ("someCondition") {
//dependency on below function
calculateEmpSal().then(function () {
deferred.resolve(empSal);
}, function () {
deferred.resolve(empSal);
});
} else {
deferred.resolve(brand);
}
})
.error(function (err) {
console.log(err);
});
return deferred.promise;
}
};
}
return ['$http', '$q', '$log', 'empModule.config.configManager', 'empModule.remote.empConfig', empConfigFactory];
});
I am aware that we cannot test the private function. I just want to know how to handle the test cases in this scenario. Can we mock a private function