JiniKJohny
JiniKJohny

Reputation: 1182

Testing local methods containing service calls using Jasmine

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

Answers (1)

Dan Kuida
Dan Kuida

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

Related Questions