我正在嘗試對這個彈出方法進行單元測驗,但我不能,你能幫忙嗎
openPram(): void {
const dialogConfig = new MatDialogConfig();
this.dialog.open(ParamGameComponent, dialogConfig);
}
uj5u.com熱心網友回復:
由于這里沒有很多代碼并且沒有說明您要測驗的內容。我將假設您要測驗使用 ParamGameComponent 的引數和 dialogConfig const 呼叫的 dialog.open() 。如果這是真的,那么您的測驗可能如下所示:
it('open dialog test', () => {
const openDialogSpy = spyOn(component.dialog, 'open')
const fakeDialogConfig = new MatDialogConfig;
component.openPram();
expect(openDialogSpy).toHaveBeenCalledWith(ParamGameComponent,
fakeDialogConfig);
});
此測驗中的組件 var 還假設您擁有默認的 Angular CLI 生成的 spec.ts 檔案,該檔案創建您正在為其撰寫測驗的組件的本地實體。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/345348.html
