0
角度/バックボーンを使用しないJavascriptモジュラーアプリケーションがあります。 スタートアップモジュールのテストケースを作成しようとしていますが、問題に直面しています。ジャスミンを使用したモック依存のモジュール
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をモックする必要があります。
このシナリオでどのようにテストケースを書くことができますか教えてください。