I am trying to write some UI tests using testbed for a couple of components and I am stuck at this. The regular way to trigger a click seems to not work with ion-checkbox.
this is my view:
<ion-checkbox
item-right
(ionChange)="checkboxOptionChanged($event, 'isActive')"
[checked]="generalOptions.isActive"
>
</ion-checkbox>
ionChange
just calls a function in my service
public checkboxOptionChanged(event: CustomEvent<IonCheckbox>, key: keyof GeneralOptions): void {
this.myService.updateGeneralOptionsWith({
[key]: event.detail.checked,
});
}
in my Test I get the reference to the HTML object (or the DebugElement
) and I trigger a click but it does not call the ionChange
event listener.
Does anyone knows how to do it?
As workaround I am just dispatching a custom event:
const myEvent = new CustomEvent('ionChange', {detail: myCheckBoxHTMLElement});
myCheckBoxHTMLElement.dispatchEvent(myEvent);
But that seems really easy to break if (for example) I use another event like click
or onChanges
1 post - 1 participant