Я пишу тесты для компонента, который динамически инициализируется как модальный (entryComponent). Входы для этого компонента извлекаются через инжектор.
Мне нужен способ предоставить эти входные данные на этапе создания компонента в beforeEach.
this.modalService.create({
component: sampleComponent, inputs: {
test: 'testMsg'
}
});
SampleComponent:
@Modal()
@Component({
selector: 'sample-component',
templateUrl: './sample.component.html',
styleUrls: ['./sample.component.scss']
})
export class SampleComponent implements OnInit {
test: string;
constructor(private injector: Injector) {
}
ngOnInit() {
this.test= this.injector.get('test');
}
}
Тест для образцаКомпонент:
describe('sampleComponent', () => {
let component: SampleComponent;
let fixture: ComponentFixture<SampleComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SampleComponent],
imports: [
ModalModule,
BrowserAnimationsModule,
],
providers: [
ModalService,
]
})
.compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(SampleComponent);
component = fixture.componentInstance;
fixture.detectChanges();
component.ngOnInit();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
тест не пройден с:
Ошибка: StaticInjectorError (DynamicTestModule) [тест]:
StaticInjectorError (Платформа: ядро) [тест]:
NullInjectorError: Нет провайдера для теста!
Как обеспечить значение для «теста» в этом случае?