0
我是新来qunit + sinon.js,我想要写一个函数onMultiSelectPress
一个单元测试,所以我需要模拟:如何在ui5中查看模型?
this.myController._oList
this.myController.getResourceBundle()
this.myController.getModel("masterView")
权?
我被困在得到一个存根getModel("masterView")
,有什么建议吗?
onInit : function() {
var oList = this.byId("list"),
oViewModel = this._createViewModel();
this._oList = oList;
this.setModel(oViewModel, "masterView");
},
_createViewModel : function() {
return new JSONModel({
isFilterBarVisible: false,
filterBarLabel: "",
delay: 0,
title: this.getResourceBundle().getText("masterTitleCount", [0]),
noDataText: this.getResourceBundle().getText("masterListNoDataText"),
sortBy: "Name",
groupBy: "None",
listMode: "SingleSelectMaster",
showDeleteButton: false
});
},
getModel : function (sName) {
return this.getView().getModel(sName);
},
onMultiSelectPress : function() {
var oMasterViewModel = this.getModel("masterView");
switch(this._oList.getMode()) {
case "MultiSelect":
oMasterViewModel.setProperty("/listMode", "SingleSelectMaster");
oMasterViewModel.setProperty("/showDeleteButton", false);
break;
case "SingleSelectMaster":
oMasterViewModel.setProperty("/listMode", "MultiSelect");
oMasterViewModel.setProperty("/showDeleteButton", true);
break;
}
},
如何在单元测试onInit方法?我可以测试方法的存在,但无法弄清楚在它内部测试JSON。 '的OnInit:函数的OnInit(){ 绑定到格式化的文本控制// HTML字符串 VAR oModel =新JSONModel({ 标题: '你好', 消息: '
你
' + 接受:“我接受', 下降:'我拒绝' });这个.getView()。setModel(oModel); }, ' – user557657'assert.ok(this.getView()。getModel(oModel))'? @ user557657 – Tina
我无法在单元测试中获得'this'引用。 – user557657