diff --git a/test/common/services/HttpClient.test.ts b/test/common/services/HttpClient.test.ts index 63a2307d..b894cd32 100644 --- a/test/common/services/HttpClient.test.ts +++ b/test/common/services/HttpClient.test.ts @@ -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();