Когда я использую следующую службу в компоненте, отображается ошибка «TypeError: невозможно прочитать свойство 'next' of undefined», и тесты, которые ранее не вызывали никаких проблем, также терпят неудачу.
Service:
export class DataService {
loadData$: Observable<string>;
observerLoadData: Observer<string>;
constructor() {
this.loadData$ = new Observable(observer => this.observerLoadData = observer);
this.startObs();
}
startObs() {
setTimeout(() => {
this.observerLoadData.next('LOADEDDATA$');
console.log('huhu');
}, 2500); }
}
Компонент:
....
constructor(private dataService: DataService) {
this.dataService.loadData$.subscribe(value => this.loadedData = value);
}
....
Технические характеристики:
....
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
providers: []
,
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
de = fixture.debugElement.query( By.css('form') );
el = de.nativeElement;
});
....