我使用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!
提前感谢任何试图帮助我的人。