mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Improved HttpClientTest
This commit is contained in:
parent
059fa37ca7
commit
cb76c89a08
1 changed files with 19 additions and 2 deletions
|
@ -7,14 +7,14 @@ describe('HttpClient', () => {
|
|||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
describe('fetchJson', () => {
|
||||
it('throws json when response is not ok', async () => {
|
||||
it('throws json on success', async () => {
|
||||
const theError = { error: true, foo: 'bar' };
|
||||
fetch.mockResolvedValue({ json: () => theError, ok: false });
|
||||
|
||||
await expect(httpClient.fetchJson('')).rejects.toEqual(theError);
|
||||
});
|
||||
|
||||
it('return json when response is ok', async () => {
|
||||
it('return json on failure', async () => {
|
||||
const theJson = { foo: 'bar' };
|
||||
fetch.mockResolvedValue({ json: () => theJson, ok: true });
|
||||
|
||||
|
@ -24,6 +24,23 @@ describe('HttpClient', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('fetchEmpty', () => {
|
||||
it('returns empty on success', async () => {
|
||||
fetch.mockResolvedValue({ ok: true });
|
||||
|
||||
const result = await httpClient.fetchEmpty('');
|
||||
|
||||
expect(result).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('throws error on failure', async () => {
|
||||
const theError = { error: true, foo: 'bar' };
|
||||
fetch.mockResolvedValue({ json: () => theError, ok: false });
|
||||
|
||||
await expect(httpClient.fetchJson('')).rejects.toEqual(theError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchBlob', () => {
|
||||
it('returns response as blob', async () => {
|
||||
const theBlob = new Blob();
|
||||
|
|
Loading…
Reference in a new issue