你不是在展示你
.spec.ts
表单出现问题的原因是,在spec文件中,也需要像这样导入相关模块:
describe('ExampleComponent', () => {
let component: ExampleComponent
let fixture: ComponentFixture<ExampleComponent>
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
TranslateModule.forRoot({
loader: {provide: TranslateLoader, useClass: TranslateFakeLoader}
}),
HttpClientModule,
HttpClientTestingModule,
FormsModule,
SfFormModule,
ReactiveFormsModule,
NguiAutoCompleteModule,
NgxMyDatePickerModule,
NgxPermissionsModule.forRoot(),
PipeModule,
StoreModule.forRoot({}),
LayoutsModule
],
declarations: [
ExampleComponent
],
providers: [
{provide: APP_BASE_HREF, useValue: '/'},
{provide: ToastrService, MockToastrService},
ActionsSubject,
SimService
]
}).compileComponents()
}))
beforeEach(() => {
fixture = TestBed.createComponent(ExampleComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy()
})
})
在这种情况下,您需要在spec文件中导入FormsModule和/或ReactiveFormsModule以及prob其他内容。
为了减少导入的数量,您可以将自己的模块导入spec文件(例如AccountModule和/或AppModule),因为它们已经导入了表单内容。