我有以下控制器方法:
function changeItem(itemList) {
vm.selectedItem = '';
if(itemList !== null || itemList !== '' && itemList !== undefined){
if (itemList.guestFirstName !== '' &&
itemList.guestFirstName !== undefined &&
itemList.guestFirstName !== null) {
vm.selectedItem += itemList.guestFirstName + ' ';
}
if (itemList.guestLastName !== '' &&
itemList.guestLastName !== undefined &&
itemList.guestLastName !== null) {
vm.selectedItem += itemList.guestLastName + ' ';
}
Iif (itemList.type !== '' &&
itemList.type !== undefined &&
itemList.type !== null) {
vm.selectedItem += itemList.type + '-';
}
if (itemList.id !== '' &&
itemList.id !== undefined &&
itemList.id !== null) {
vm.selectedItem += itemList.id + ' ';
if (itemList.id === "All") {
vm.selectedId.push(vm.itemLists.id);
}
else {
vm.selectedId = itemList.id;
}
}
}
}
}
规范.js:
t('listController - changeItem()', inject(function () {
var itemList = [
{
"id":111,
"guestfirstName":"Test",
"guestlastName":"Test",
"type":"BUSINESS"
},
{
"id":222,
"guestfirstName":"Test",
"guestlastName":"Test",
"type":"BUSINESS"
},
];
var selectedItem = "Test Test BUSINESS-111"
controller.changeItem(itemList);
scope.$apply();
expect(controller.selectedItem).to.equal(selectedItem);
expect(controller.selectedId).to.equal(itemList[0].id);
}));
但是,当我运行测试时,它说语句和分支除了函数之外没有被覆盖。
谢谢