Suppose we have this method in a service that return an Observable:
getSearchResults(request: LocationSearchRequest){
return this.http.get(this.getApiUrl(request))
.map(res => <LocationSearchResponse> res.json())
.catch(this.handleError);
}
How can I modify this code to return the mocked data ratehr then making an actual GET requesr?
import { MOCKEDDATA } from './mocked-data';
It's not a duplicate question. This has nothing to do with testing, jasmine and angualr2 testing api.
Xavi's answer is great and simple, but it didn't work for me - I tweaked it like so:
import { of } from 'rxjs';
And then:
return of(MOCKEDDATA);
Hope this helps someone else too!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With