为什么我需要IonicModule.forRoot(MyComponent)才能在测试中的组件中使用InfiniteScroll

时间:2018-02-07 12:50:01

标签: angular ionic3 jestjs

我使用Angular 5,Ionic 3和Jest的堆栈来测试我的应用程序中的组件。现在,测试看起来像这样:

describe("Feed Page", () => {

  let component: FeedPage;
  let fixture: ComponentFixture<FeedPage>;

  beforeEach( async() => {
    TestBed.configureTestingModule({
      declarations: [ FeedPage, VideoFrameComponent ],
      imports: [
        IonicModule.forRoot(FeedPage),
      ],
      providers: [
        { provide: CustomErrorHandler, useClass: CustomErrorHandlerMock },
        { provide: NavController, useClass: NavControllerMock },
        { provide: LoadingController, useClass: LoadingControllerMock },
        { provide: VideosServiceProvider, useClass: VideosServiceMock }
      ]
    });
    TestBed.compileComponents();
  });

  beforeEach( () => {
    fixture = TestBed.createComponent( FeedPage );
    component = fixture.componentInstance;
  });

  it("can be instancied", () => {
    expect(component).toBeDefined();
  });
});

有很多设置和一个测试来检查一切是否正常。 FeedPage组件使用Ionic 3中的InfiniteScroll。如果我在运行测试时更改IonicModule.forRoot(FeedPage) IonicModule,则会出现此错误:

StaticInjectorError(DynamicTestModule)[InfiniteScrollContent -> Config]: 
  StaticInjectorError(Platform: core)[InfiniteScrollContent -> Config]: 
    NullInjectorError: No provider for Config!

提前感谢任何试图帮助我的人。

0 个答案:

没有答案