Original service
getVersionDataValuesforPopup(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(responce => <CoCCreateVersionPopupPage[]>responce.json())
.catch(error => {
return error;
});
}
Calling original service in component
this.createversionservice.getVersionDataValuesforPopup(this.cocviewversiondatapage.docVersion,
this.cocviewversiondatapage.VersionDescriptions,
this.cocviewversiondatapage.structWeek, dataitems.DocumentVersionFieldId, this.cocviewversiondatapage.Id,
this.cocviewversiondatapage.WLTP)
.then(
data=> { ...});
Mock service via constructor injection
getVersionDataValuesforPopup(Docversion, versionname, Structureweek, docVersionFieldID, versionid, WLTP) {
return Observable.of({ Result: {} });
}
I got an error while test the method
TypeError: this.createversionservice.getVersionDataValuesforPopup(...).then is not a function
I know the reason for the error, I am using Observable in my mock service but the real service has promise, So then callback does not support.Kindly let me know how can write a mock service for a http promise service call.
return new Promise((resolve) => { resolve(null); });