HttpMock
Http Mocker for easy to http testing using Jest
When using this mocking helper you need to call Http.onGet()
before Http instance is created
Static Method Summary
| Static Public Methods | ||
| public static |
Mocks responses for delete methods |
|
| public static |
Mocks responses for get methods You may pass a specific endpoint as parameter to mock only selected endpoints. |
|
| public static |
Mocks responses for post methods |
|
| public static |
Mocks responses for put methods |
|
| public static |
reset() Resets all mocked behavior |
|
Static Public Methods
public static onDelete(endpoint: string): MockBehavior source
Mocks responses for delete methods
Params:
| Name | Type | Attribute | Description |
| endpoint | string |
Return:
| MockBehavior |
public static onGet(endpoint: string): MockBehavior source
Mocks responses for get methods You may pass a specific endpoint as parameter to mock only selected endpoints. This is very useful, when having methods that do several Http requests, so you can mock them one on one.
The following code returns the same content on every get call
HttpMock.onGet().reply(200, [{login: 'foo'}, {login: 'bar'}]);
The next code returns the different content depending on the passed endpoint
HttpMock.onGet('/foo').reply(200, {data: 'foo'});
HttpMock.onGet('/bar').reply(200, {data: 'bar'});
Params:
| Name | Type | Attribute | Description |
| endpoint | string |
Return:
| MockBehavior |
public static onPost(endpoint: string): MockBehavior source
Mocks responses for post methods
Params:
| Name | Type | Attribute | Description |
| endpoint | string |
Return:
| MockBehavior |
