How to write testcases for click event on addEventListener in Angular

Viewed 81

How to write testcases for the below functions in Angular TypeScript using Jasmine-karma.

private element: any;
@Input() id: string;

constructor(private el: ElementRef) {
  this.element = el.nativeElement;
}

ngOnInit(): void {
  if (!this.id) {
    return;
  }
  this.element.addEventListener("click", (el: any) => {
    if (el.target.className === "tfb-modal-background") {
      this.close();
    }
  });
}
0 Answers
Related