0
我有一些代碼,看起來像這樣:測試一個構造函數實例化另一個類
var testLib = function(params) {
this.conf = new testLib.Config(params);
};
testLib.Config = function(params) {
//do stuff with params
};
實例化,像這樣:
var ins = new testLib({});
我想測試的tesLib構造正確實例化的配置與用茉莉花糾正爭論。我試試這個:
spyOn(window,'testLib.Config');
var test = new testLib('testparam');
expect(testLib.Config).toHaveBeenCalledWith('testparam');
但是這不起作用。我收到一個錯誤,說testLib.Config方法不存在。它確實存在,因爲我包括我的整個圖書館,所以它可用於茉莉花。
我該如何測試?