我刚创建了一个带有Ionic cli的应用程序,使用带有菜单的模板。
我已经设置了所有的测试配置。我的TestBed看起来像这样
TestBed.configureTestingModule({
declarations: [MyApp],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
],
providers: [
{ provide: StatusBar, useFactory: () => StatusBarMock.instance() },
{ provide: SplashScreen, useFactory: () => SplashScreenMock.instance() },
],
});模拟来自ionic-mocks
import { StatusBarMock, SplashScreenMock } from 'ionic-mocks';我的考试通过了
beforeEach(() => {
fixture = TestBed.createComponent(MyApp);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('component is created', () => {
expect(component).toBeTruthy();
});但我得到了这个“警告”:
错误:“未处理的承诺拒绝:”,“没有为HomePage找到组件工厂。您是否将其添加到@NgModule.entryComponents中?”,
HomePage在MyApp's @NgModule on entryComponents上,我必须把它也包括在TestBed上吗?怎么写?
发布于 2018-01-23 06:07:04
只需将组件添加到条目组件:
TestBed.configureTestingModule({
declarations: [MyApp],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
],
entryComponents: [MyApp] <-------------------
});也可以使用要测试的组件导入模块:
TestBed.configureTestingModule({
declarations: [MyApp],
imports: [
AppModuleWithHomePageComponent, <--------------
BrowserModule,
IonicModule.forRoot(MyApp),
],https://stackoverflow.com/questions/48391130
复制相似问题