Is there a way to include ControlContainer
in an Angular unit test?
The error message I am encountering reads:
NullInjectorError: StaticInjectorError(DynamicTestModule)[ChildFormComponent -> ControlContainer]:
StaticInjectorError(Platform: core)[ChildFormComponent -> ControlContainer]:
NullInjectorError: No provider for ControlContainer!
This is my attempt at including ControlContainer
:
beforeEach(() => {
const parentFixture = TestBed.createComponent(ParentFormComponent);
const parentComponent = parentFixture.componentInstance;
parentComponent.initForm();
fixture = TestBed.createComponent(ChildFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
I have come across solutions that involve:
declarations: [
...MY_DECLARATIONS
],
imports: [
...MY_IMPORTS
],
providers: [
{
provide: ControlContainer,
useValue: MyFormGroupDirective
}
]
I have not been successful with this approach so far. Any guidance on this matter would be greatly appreciated.