我在我的SAPUI5應用如何在QUnit中存儲返回對象的函數?
var dateVal = controls.awardDate.getDateValue();
var month = dateVal.getMonth();
awardDate是用戶輸入的日期,並返回一個JavaScript日期對象一個datepicker以下行。這是我測試這個元素的一個片段。
awardDate: {
getValue: getInvalidValue,
getValueState: getValueStateWarning,
setValue: setValue,
getDatevalue: getDateValue
}
在我qunit中,我得到一個錯誤,說對象不支持屬性或方法'getDateValue'。我不知道當它返回一個對象時我該如何存儲這個函數。其他測試我這樣做
var getValue = sinon.stub().returns('');
其中我得到一個空字符串。 所以我在與日期選擇器做的嘗試是
var getDateValue = sinon.stub().returns(new Date());
但這不起作用。我仍然得到同樣的錯誤。有沒有人做過這個?
編輯/更新:我能夠做解決問題的一部分,下面
var getValueDate = sinon.stub().returns(Object, function(){ });
現在我的問題是相同的錯誤,但爲得到月()返回一個字符串。所有其他變量都是全局變量,但dateVal是在用戶更新日期選擇器時現場創建的。關於如何繼續這個的任何想法?