如何模拟组件实例事件

时间:2019-10-29 10:46:58

标签: angular angular-material karma-jasmine material-dialog ts-mockito

我想测试一个事件(dialogEvent,该事件是通过material dialogts-mockito实例触发的:

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

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

如何在测试中监视或模拟它?

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

0 个答案:

没有答案