我正在模块中导入AccordionModule
。但是使用“ ng test
”,我在控制台中遇到了错误-
Error: StaticInjectorError[AccordionComponent]:
StaticInjectorError[AccordionComponent]:
NullInjectorError: No provider for AccordionComponent!
我已经尝试将其导入spec.ts
文件和component.ts
文件中,但是仍然会出现此错误。
规范文件:
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [AccordionModule.forRoot()],
declarations: [CBenefitComponent], providers: [DataService]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CBenefitComponent);
component = fixture.componentInstance; fixture.detectChanges();
});
fit('should create', () => {
expect(component).toBeTruthy();
});
和CAFDetailModule:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule} from '@angular/forms';
import { AccordionModule } from 'ngx-bootstrap/accordion';
@NgModule({
imports: [ ReactiveFormsModule, CommonModule, AccordionModule.forRoot()
],
exports: [AccordionModule],
})
export class CAFDetailModule {
constructor(){
console.log('detail module loaded'); }
}