**testservice.ts**
import { LoaderDialog } from './loader.component';
import { MatDialog } from '@angular/material/dialog';
export class TestService {
constructor(public dialog: MatDialog) {}
dialogRef:any;
show() {
this.dialogRef = this.dialog.open(LoaderDialog, {
disableClose: true,
panelClass: 'transparent-background'
});
}
**testcomponent.ts**
constructor(private apiServ:ApiServeService, private dialog: MatDialog, private loader: TestService) {
this.loader.show();
}
当我为testcomponent
运行测试用例时,我得到了以下内容
错误:“找不到LoaderDialog的组件工厂”。
答案 0 :(得分:0)
我找到了解决此问题的方法。我们需要使用2个参数将'overrideModule'添加到我们的测试规范文件的beforeEach函数中,并将该组件也添加到声明部分。
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DataCenterComponent, **LoaderDialog**]
})
**.overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [LoaderDialog] } })**
}));