У меня есть компонент FAB, разделенный на 3 части: компонент триггера, компонент действий и основной компонент, собирающий все вместе.
Компоненты Trigger и Actions имеют внедренного родителя, например:
constructor(
@Inject(forwardRef(() => FabSpeedDialComponent)) private _parent:
FabSpeedDialComponent,
private renderer: Renderer
) { }
Родитель имеет круговую зависимость от своих действий: @ContentChild(FabSpeedDialActionsComponent) _childActions: FabSpeedDialActionsComponent;
Он отлично работает, но у меня проблемы с тестированием такого поведения. Например, есть тест на компонент actions:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FabSpeedDialActionsComponent } from './fab-speed-dial-actions.component';
describe('FabSpeedDialActionsComponent', () => {
let component: FabSpeedDialActionsComponent ;
let fixture: ComponentFixture<FabSpeedDialActionsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [FabSpeedDialActionsComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FabSpeedDialActionsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fit('should create', () => {
expect(component).toBeTruthy();
});
});
Это не сработает с этой ошибкой:
Error: StaticInjectorError(DynamicTestModule)[FabSpeedDialActionsComponent -> FabSpeedDialComponent]: StaticInjectorError(Platform: core)[FabSpeedDialActionsComponent -> FabSpeedDialComponent]: NullInjectorError: No provider for FabSpeedDialComponent!
Даже если я попытаюсь добавить его в объявления, все равно ничего не получится.
@trichetriche там о неработающих сервисах, а не о компонентах. Ни слова о компонентах forwardRef.
Вы, видимо, пропустили часть насмешек.
Вы пробовали добавить FabSpeedDialComponent в список поставщиков TestBed? то есть: после объявлений добавьте запятую, а затем новую строку с providers: [FabSpeedDialComponent]. Вы также можете издеваться над FabSpeedDialComponent и вместо этого вставить шпион / макет.



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)

