Providing “entryComponents” for a TestBed

前端 未结 2 663
余生分开走
余生分开走 2021-02-01 01:05

I have a component which receives a component class of component to dynamically create as a child.

let componentFactory = this.componentFactoryResolver.resolveC         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 01:53

    Okay, I figured it out. In the test you should define new module where you declare your mock component and specify it as an entryComponent too.

    @NgModule({
      declarations: [TestComponent],
      entryComponents: [
        TestComponent,
      ]
    })
    class TestModule {}
    

    And import it into TestBed

    TestBed
      .configureTestingModule({
        declarations: [ValueComponent, TestHostComponent],
        imports: [TestModule],
      });
    

    I hope it will help someone :]

提交回复
热议问题