How to mock component instance event

264 Views Asked by At

I want to test an event (dialogEvent) which is being triggered from a material dialog instance with ts-mockito:

myFunc() {
    this.matDialogRef = this.matDialog.open(DialogComponent);

    this.matDialogRef.componentInstance.dialogEvent.subscribe(() => {
        this.doSomething();
    });
}

How can I spy on or mock it in my test?

it('should call doSomething() on dialogEvent', () => {
    // trigger DialogComponent.dialogEvent event here
    expect(comp.doSomething).toHaveBeenCalled();
});
0

There are 0 best solutions below