Version 0.7.0 RC
Pre-release
Pre-release
-> Add a mock feature.
Mocks calls
To have a feature to enable mocks api. When enabled, will call directly the function rather than call the http request.
To enable Mocks : in a module provider use this :
providers: [{ provide: HTTP_ANNOTATIONS_USE_MOCKS, useValue: true }]
You can specify a boolean value, or have a specific function, that will be used to know if the apps will use mock. This could help you to define mock only for specific call.
providers: [{ provide: HTTP_ANNOTATIONS_USE_MOCKS, useValue: (url, requestType, params, args): boolean => {
console.log('useMock : ', url, requestType, params, args);
return requestType === 'Get' ? true : false;
} }]
define your mocks by return a fake observable, with your mock data.
@GET
@Path('posts/:id')
public getPost(@PathParam('id') id: number): Observable<any> {
return of([{id: id, title: 'mock true'}]);
}