From d590a3b7db59336ca1da9055f16a542daf68ac79 Mon Sep 17 00:00:00 2001 From: Arne Vandoorslaer Date: Wed, 16 Jun 2021 08:17:58 +0200 Subject: [PATCH] fix: Await unhandled promises in sdk tests (#101) * fix: removed UnhandledPromiseRejectionWarning in SDK * fix: made tests async --- .../query-component-remote.service.spec.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/semcom-sdk/lib/component/services/query-component-remote.service.spec.ts b/packages/semcom-sdk/lib/component/services/query-component-remote.service.spec.ts index 3609aad8..e63ba512 100644 --- a/packages/semcom-sdk/lib/component/services/query-component-remote.service.spec.ts +++ b/packages/semcom-sdk/lib/component/services/query-component-remote.service.spec.ts @@ -10,17 +10,18 @@ describe('QueryComponentRemoteService', () => { }); - it('should send get request to repository url', () => { + it('should send get request to repository url', async () => { const service = new QueryComponentRemoteService('test'); const mockFetch = jest.fn().mockImplementation(() => Promise.resolve({ json: () => Promise.resolve({}), + ok: true, })); window.fetch = mockFetch; - service.query({}); + await service.query({}); expect(fetch).toBeCalledWith('test/component/query', { body: '{}', @@ -33,7 +34,7 @@ describe('QueryComponentRemoteService', () => { }); - it('should throw error when request fails', () => { + it('should throw error when request fails', async () => { const service = new QueryComponentRemoteService('test'); @@ -44,9 +45,7 @@ describe('QueryComponentRemoteService', () => { window.fetch = mockFetch; - service.query({}); - - expect(fetch).rejects.toThrow(); + await expect(service.query({})).rejects.toThrow(); }); @@ -54,7 +53,7 @@ describe('QueryComponentRemoteService', () => { const service = new QueryComponentRemoteService('test'); - expect(service.query(null)).rejects.toThrow(); + await expect(service.query(null)).rejects.toThrow(); }); @@ -62,7 +61,7 @@ describe('QueryComponentRemoteService', () => { const service = new QueryComponentRemoteService(null); - expect(service.query({})).rejects.toThrow(); + await expect(service.query({})).rejects.toThrow(); });