mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 01:37: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);
|
beforeEach(jest.clearAllMocks);
|
||||||
|
|
||||||
describe('fetchJson', () => {
|
describe('fetchJson', () => {
|
||||||
it('throws json when response is not ok', async () => {
|
it('throws json on success', async () => {
|
||||||
const theError = { error: true, foo: 'bar' };
|
const theError = { error: true, foo: 'bar' };
|
||||||
fetch.mockResolvedValue({ json: () => theError, ok: false });
|
fetch.mockResolvedValue({ json: () => theError, ok: false });
|
||||||
|
|
||||||
await expect(httpClient.fetchJson('')).rejects.toEqual(theError);
|
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' };
|
const theJson = { foo: 'bar' };
|
||||||
fetch.mockResolvedValue({ json: () => theJson, ok: true });
|
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', () => {
|
describe('fetchBlob', () => {
|
||||||
it('returns response as blob', async () => {
|
it('returns response as blob', async () => {
|
||||||
const theBlob = new Blob();
|
const theBlob = new Blob();
|
||||||
|
|
Loading…
Reference in a new issue