I have an original service (in angular 5) with API that returns Observable.
I need to create similar mock service called ServiceStub. In the mock I provide this API definition (same signature as original) but reading from a local json file:
public myAPI(): Observable<CompleObject[]> {
const x = this.httpClient.get('..//stubs/myJsonFile.json');
return Observable.of(x) // syntax error here
}
so in the module where the original service is provided, I replace this line:
OriginalService
(in the providers array) by
{ provide: OriginalService, useClass: ServiceStub },
Running the app, with a small modification to myAPI() in the mock just to get it to build, I get that the original is still called instead of the mock. Despite of the previously mentioned changed to the module, where I instruct the mock to be used in all places where the original was intended.