Apologies if this has been asked before, but I couldn't find a solution to my issue.
I need to create tests for a service within an Angular JS application.
The main function of the service returns and is used as an external method. There are also a couple of helper functions like subFunc
. How can I call and test these internal functions within the service?
service.js
function TestService() {
return {
mainFunc: mainFunc
};
function mainFunc() {
//do something and call subFunc()
subFunc(a)
}
function subFunc(a) {
if (a === 1) {
// ... do magic 1
return true;
} else {
// ... do magic 2
return false;
}
}
}
})()
service.spec.js
describe('Test Service', function() {
beforeEach(module('TestService'));
var TestService;
beforeEach(inject(function($injector) {
TestService = $injector.get('TestService');
}));
it('should return true if subFunc is called with 1', function () {
// ....
});
})