I have a component with the following function:
@Output() data: EventEmitter<any> = new EventEmitter();
testData() {
observableRef.subscribe(() => {
this.data.emit();
}, () => {
this.data.emit();
});
}
I am trying to write unit test cases for this function. Here is what I have tried so far:
it('should call testData method', fakeAsync(() => {
fixture.detectChanges();
spyOn(observableRef, 'emit’);
component.testData(component.data);
expect(component.data.emit).toHaveBeenCalled();
tick();
discardPeriodicTasks();
}));
However, when running this test case, the code coverage does not enter the subscribe function. As a newbie in unit testing, I am unsure why this is happening. Can someone please guide me on how to properly test the subscribe function and improve my test case?