Reputation: 1182
I am facing an issue with testing a local method in my Angular JS controller.
I need to test retrieveRuleDetails
method which contains a service call, but not able to proceed. Please help to test the below code:
var retrieveRuleDetails = function(feeId, ruleId) {
$rootScope.triggerLoading(true);
FeesRulesService.getRule(feeId, ruleId)
.then(getRuleSuccess)
.catch(getRuleFail);
};
Upvotes: 0
Views: 31
Reputation: 1057
I think best would be to pass FeesRulesService as a paramter - a spy in jasmine and than to test getRule is invoked
FeesRulesServiceMock= {
getRule: function(feeId,ruleId) {
}
};
spyOn(FeesRulesServiceMock, 'getRule');
retrieveRuleDetails(feeId,ruleId,FeesRulesServiceMock)
it("bla bla",function(){
expect(FeesRulesServiceMock.getRule).toHaveBeenCalled();
expect(FeesRulesServiceMock.getRule).toHaveBeenCalledWith(feeId,ruleId);
});
Upvotes: 1