Unique service
fetchPopupData(Docversion, versionname, Structureweek, docVersionFieldID, versionid, WLTP) {
return this.http.get(this.apiUrl + 'GetElementPopUpData?docVersion=' + Docversion + '&versionVariant=' + versionname
+ '&structureWeek=' + Structureweek + '&docVersionFieldID=' + docVersionFieldID
+ ' &VersionId=' + versionid + ' &isWLTP=' + WLTP, { withCredentials: true })
.toPromise().then(response => <CoCCreateVersionPopupPage[]>response.json())
.catch(error => {
return error;
});
}
Using the unique service in component
this.popupService.fetchPopupData(this.docInfo.version,
this.docInfo.versionName,
this.docInfo.week, this.docInfo.fieldID, this.docInfo.id,
this.docInfo.WLTP)
.then(
data=> { ...});
Simulated service using constructor injection
fetchPopupData(Docversion, versionname, Structureweek, docVersionFieldID, versionid, WLTP) {
return Observable.of({ Result: {} });
}
An error occurred during testing of the method
TypeError: this.popupService.fetchPopupData(...).then is not a function
I understand the cause of the error - I am using Observable
in my simulated service while the actual service relies on promise
, causing issues with the then callback. Please advise on how to create a simulated service for an http
promise service call.