Я использую Observable для подписки на события, но не могу его проверить
Вот мой код
Сервис
export class EventService<T> {
private eventSubject = new Subject<string>();
eventSubject$ = this.eventSubject.asObservable();
dispathEvent(name) {
this.eventSubject.next(name);
}
}
Компонент
export class UserComponent implements OnInit{
getSub: Subscription;
constructor(private service EventService, private otherService OtherServece)(){}
ngOnInt(){
this.getSub = this.service.eventSubject$.subscribe(name =>{
this.otherService.performAction();
this.otherService.setVar = name;
})
}
}
Spe c Файл
let mockEventService :any;
mockEventService = {
eventSubject: jasmine.createSpyObj('eventSubject', ['next']),
eventSubject$: jasmine.createSpyObj('eventSubject$', ['subscribe']),
};
//some code
providers: [{ provide: EventService, useValue: mockEventService }]
// some code
fixture = TestBed.createComponent(UserComponent);
component = new TeamOvertimeComponent(mockEventService ,mockOtherService);
....
it('should test ngOnInt Service var status', () => {
expect(mockEventService.eventSubject$['subscribe']).toHaveBeenCalled()
fixture.detectChanges();
//
component.ngOnInit();
});
Я вижу проблему как
TypeError: this.service.eventSubject$.subscribe is not a function
I пытался сохранить их перед каждым, но проблема все еще существует