我有一个材质对话框组件,我试图将其打开,然后单击“确认”按钮,该对话框位于我的模态中,但是我遇到此错误:
TypeError:confirmButton为null http:// localhost:9876 / karma_webpack /main.js(第20740行)
我尝试过:
it('should open the modal and click in the confirm button', () => {
spyOn(component.dialog,'open').and.callThrough();
component.openDialog();
const confirmButton = fixture.debugElement.query(By.css('#dialog-confirm-button'));
confirmButton.triggerEventHandler('click', null);
// my expect will be there later
});
这是我的对话框:
<div>
<div mat-dialog-content>
Opened dialog
</div>
<div mat-dialog-actions align="center">
<button id="dialog-confirm-button" [mat-dialog-close]="true" mat-flat-button
color="accent">Confirm</button>
<button id="dialog-cancel-button" [mat-dialog-close]="false" mat-flat-button color="primary">
Cancel
</button>
</div>
</div>
这是我的openDialog()
函数:
openDialog(): Observable<boolean> {
const dialogRef = this.dialog.open(DialogComponent);
return dialogRef.afterClosed();
}