0
我有一個Javascript模塊化應用程序不使用Angular/Backbone。 我正在嘗試爲我的啓動模塊編寫測試用例,但面臨問題。使用Jasmine嘲笑從屬模塊
Startup.js:
window.claimStartup = function (options) {
this.options = $.extend({}, this.options, options);
this.cmds = new this.serviceModule(this);
}
getClaimsCategories: function (claimTypeCode) {
var self = this;
// Refresh claim categories
return $.when(self.cmds.getClaimsCategories(claimTypeCode))
.then(function (response) {
return response;
});
},
Service.js:
claimStartup.prototype.serviceModule = function (cfg) {
this.cfg = cfg;
this.init();
}
StartUp.spec.js:
var claimStartUp;
beforeEach(function() {
spyOn(window.claimStartup.prototype, 'serviceModule');
claimStartUp = new window.claimStartup();
});
it("should be able to get categories", function() {
jasmine.spyOn(claimStartUp.cmds, 'getClaimsCategories').andReturn('XYZ');
var categories= claimStartup.getClaimsCategories('ABC');
expect(categories).toEqual('XYZ');
});
填充this.cmds時收到錯誤,它說serviceModule構造函數沒有定義,實際上我需要在聲明claimStartup時初始化serviceModule。
請讓我知道如何在這種情況下編寫測試用例。