我想测试一个事件(dialogEvent
,该事件是通过material dialog从ts-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();
});