I am testing a component which has a click input on a div.
<div (click)="handleClick(someArgs)"></div>
Now I want to validate the behaviour in a test. I tried using .click()
on the native element:
const elem = fixture.debugElement.query(By.css('my-selector'));
elem.nativeElement.click();
// Check for desired changes
However this only works in specific browsers since .click()
seems to only be defined for HTMLInputElements (Relevant StackOverflow). I get the following error 'undefined' is not a function (evaluating elem.nativeElement.click()')
for a couple browsers.
What is the best way to invoke a click event on a non HTMLInputElement?