I need to cover this method with Jasmine in my code
private subject = new Subject<any>();
getMessage(): Observable<any> {
return this.subject.asObservable();
}
Here is my constructor
fiscalDocument: FiscalDocumentData;
subscription: Subscription;
constructor(private _myFiscalDocumentsService: MyFiscalDocumentsService) {
this.subscription = this._myFiscalDocumentsService.getMessage().subscribe(message => {
if (message) {
this.fiscalDocument = message;
} else {
this.fiscalDocument = null;
}
});
}
I've already tried to do that in my test, I have the TestBed.confiugreTestingModule, but I won't post here because I believe that's my problem isn't there
let dummyOb: Observable<any>;
beforeEach(() => {
service = TestBed.get(MyFiscalDocumentsService);
fixture = TestBed.createComponent(MyFiscalDocumentsDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should getMessage', async () => {
let generalSpy = spyOn(service, 'getMessage' ).and.returnValue(await Promise.resolve(dummyOb));
expect(generalSpy).toHaveBeenCalled();
});
The error message: Expected spy getMessage to have been called. EDIT: I got the if condition, now I'm trying the else