我在Angular JS控制器中测试本地方法时遇到了问题。
我需要测试包含服务调用的retrieveRuleDetails
方法,但无法继续。请帮助测试以下代码:
var retrieveRuleDetails = function(feeId, ruleId) {
$rootScope.triggerLoading(true);
FeesRulesService.getRule(feeId, ruleId)
.then(getRuleSuccess)
.catch(getRuleFail);
};
答案 0 :(得分:1)
我认为最好将FeesRulesService作为参数 - 茉莉花的间谍 而且要调用getRule来调用
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);
});