0

**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();
}

when I run the test case for testcomponent I'm getting the following

error: 'No component factory found for LoaderDialog'.

Avi
  • 1,424
  • 1
  • 11
  • 32
Sathisha
  • 21
  • 2

1 Answers1

0

I have found the solution for this issue. we need to add 'overrideModule' to beforeEach function of our test spec file with 2 parameters and add the component into declarations part also.

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