【发布时间】:2018-12-27 19:57:09
【问题描述】:
我有两个模块:
- 模块 A
- 组件主页
- 组件展示
- 模块 B
- 组件自定义输入
app.module.ts(模块 A)
@NgModule({
declarations: [
HomeComponent,
PresentationComponent
],
imports: [
ModuleB
]
})
export class AppModule {
}
presentation.component.html
<custom-input><custom-input>
presentation.component.spec.ts
describe('PresentationComponent', () => {
let component: PresentationComponent;
let fixture: ComponentFixture<PresentationComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [PresentationComponent],
imports: [ModuleB]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PresentationComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
b.module.ts(模块 B)
@NgModule({
declarations: [
CustomInputComponent
],
exports: [
CustomInputComponent
]
})
export class ModubleB {
}
组件Presentation在其html中使用CustomInput标签,因此在模块B中,我导出CustomInputComponent然后将模块B导入模块A。
问题是,在Presentation Component的spec文件中,我还必须将Module B导入到Test Module中。但我有这个错误:
Component HomeComponent is not part of any NgModule or the module has not been imported into your module
我真的不明白为什么?有任何想法吗 ?谢谢!
【问题讨论】:
-
错误信息非常有用。在适当的模块声明数组中添加 HomeComponent。
-
是模块 A 你的
app.module.ts -
@DevEng 是的
-
@bodorgergely 我已经在 app.module.ts 中声明了 HomeComponent(我的描述中是模块 A)
-
也许我必须直接导入CustomInputComponent,而不是模块B?
标签: javascript angular testing module components