0
checkDefault(event) {
    try {
      this.defaultCard = event.checked;
      this.cardInfo.forEach((s) => {
        if (s.isDefault && event.checked) {
          const dialog = this.dialogService.dialogMethod(this.message.isDefaultAlertCard, this.dialogType.confirmation, true);
          dialog.afterClosed().subscribe((res) => {
            Eif (!res) {
              this.defaultCard = false;
            }
          });
        }
      });
    } catch (err) {
      this.errorObject.message = 'Error in checkDefault: ' + err && err.message ? err.message : null;
      this.sharedService.errorEmailNotification(this.storeId, this.errorObject);
      this.dialogService.dialogMethod(this.message.failedSave, this.dialogType.failure,
        true
      );
    }
  }

In this function, I covered try block but catch block was not covered. How to cover that.

My testcase for try block is

test('should create checkDefault', () => { 
    component.cardInfo = [{ isDefault: true, customer: "CustomerId", cardId: "cardId" }, { isDefault: false, customer: "CustomerId", cardId: "cardId" }];
    component.checkDefault({ checked: true });
    expect(component.checkDefault).toBeTruthy();

  });

1 Answers1

0

I Found answer for this

component.checkDefault(null);