JsMockito的验证机制对我不起作用。我的设置是我有 2 个类,Common 和 Suggestions。
MyNS.Common = function() {};
MyNS.Suggestions = function() {};
我在建议中设置了一个 Common 的实例。
MyNS.Suggestions.prototype.setCommon = function(common) {this.common = common;};
然后我使用 Common.getAdGroupId() 的返回值并使用该值调用 Suggestions.refresh()。这就是我想要测试的全部内容。
MyNS.Suggestions.prototype.init = function() {
// This is mocked to return 56 as can be seen in the test above.
var adGroupId = this.common.getAdGroupId();
this.refresh(adGroupId);
};
完整的工作示例在小提琴上:http: //jsfiddle.net/sbel/kqdTV/2/。请指教。