Below is the controller method in question:
function updateItem(itemList) {
vm.selectedItem = '';
if(itemList !== null || itemList !== '' && itemList !== undefined){
if (itemList.firstName !== '' &&
itemList.firstName !== undefined &&
itemList.firstName !== null) {
vm.selectedItem += itemList.firstName + ' ';
}
if (itemList.lastName !== '' &&
itemList.lastName !== undefined &&
itemList.lastName !== null) {
vm.selectedItem += itemList.lastName + ' ';
}
if (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;
}
}
}
}
spec.js:
t('listController - updateItem()', inject(function () {
var itemList = [
{
"id":111,
"firstName":"John",
"lastName":"Doe",
"type":"PERSONAL"
},
{
"id":222,
"firstName":"Jane",
"lastName":"Smith",
"type":"WORK"
},
];
var selectedItem = "John Doe PERSONAL-111"
controller.updateItem(itemList);
scope.$apply();
expect(controller.selectedItem).to.equal(selectedItem);
expect(controller.selectedId).to.equal(itemList[0].id);
}));
When running tests, it is highlighted that the statements and branches are not fully covered apart from the functions themselves.
Thank you