【问题标题】:No component factory found for LoaderDialog未找到 LoaderDialog 的组件工厂
【发布时间】:2020-03-08 01:10:48
【问题描述】:

**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 的组件工厂”。

【问题讨论】:

    标签: angular-material angular-unit-test


    【解决方案1】:

    我已经找到了解决这个问题的方法。我们需要将“overrideModule”添加到我们的测试规范文件的 beforeEach 函数中,并带有 2 个参数,并将组件也添加到声明部分。

    beforeEach(async(() => {
        TestBed.configureTestingModule({
          declarations: [ DataCenterComponent, **LoaderDialog**]
        })
        **.overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [LoaderDialog] } })**
      }));
    

    【讨论】:

      猜你喜欢
      • 2019-03-13
      • 2019-03-02
      • 1970-01-01
      • 2020-07-01
      • 2019-07-10
      • 2018-01-14
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      相关资源
      最近更新 更多