【发布时间】:2021-12-17 02:03:27
【问题描述】:
我正在尝试对这个弹出方法进行单元测试,但我不能,请你帮忙
openPram(): void {
const dialogConfig = new MatDialogConfig();
this.dialog.open(ParamGameComponent, dialogConfig);
}
【问题讨论】:
标签: angular typescript unit-testing
我正在尝试对这个弹出方法进行单元测试,但我不能,请你帮忙
openPram(): void {
const dialogConfig = new MatDialogConfig();
this.dialog.open(ParamGameComponent, dialogConfig);
}
【问题讨论】:
标签: angular typescript unit-testing
因为这里没有很多代码,也没有说明您要测试的内容。我将假设您想测试是否使用 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 文件,该文件会创建您正在为其编写测试的组件的本地实例。
【讨论】: