Mock HTTP requests in unit tests
This commit is contained in:
@@ -1,20 +1,27 @@
|
||||
import { Axios } from 'axios';
|
||||
import axios from 'axios';
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import { HeaptraderAPI } from './api';
|
||||
import { expect, jest, test } from '@jest/globals';
|
||||
|
||||
let mock: MockAdapter;
|
||||
|
||||
class HeaptraderAPITest extends HeaptraderAPI
|
||||
{
|
||||
public _mock: MockAdapter;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super("");
|
||||
mock = new MockAdapter(this._axios);
|
||||
this._mock = new MockAdapter(axios);
|
||||
this.setupMockResponses();
|
||||
}
|
||||
|
||||
setupMockResponses(): void
|
||||
{
|
||||
this._mock.onGet("/up").reply(200, {});
|
||||
}
|
||||
}
|
||||
|
||||
test('check uptime', async () => {
|
||||
const api = new HeaptraderAPI();
|
||||
await api.heartbeat();
|
||||
const api = new HeaptraderAPITest();
|
||||
const success = await api.heartbeat();
|
||||
expect(success).toBe(true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user