Skip to content

Commit

Permalink
fix: Await unhandled promises in sdk tests (#101)
Browse files Browse the repository at this point in the history
* fix: removed UnhandledPromiseRejectionWarning in SDK

* fix: made tests async
  • Loading branch information
Arne Vandoorslaer authored Jun 16, 2021
1 parent 6e1c92e commit d590a3b
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: '{}',
Expand All @@ -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');

Expand All @@ -44,25 +45,23 @@ describe('QueryComponentRemoteService', () => {

window.fetch = mockFetch;

service.query({});

expect(fetch).rejects.toThrow();
await expect(service.query({})).rejects.toThrow();

});

it('should throw error when querying if filter is not set', async () => {

const service = new QueryComponentRemoteService('test');

expect(service.query(null)).rejects.toThrow();
await expect(service.query(null)).rejects.toThrow();

});

it('should throw error when querying if repository is not set', async () => {

const service = new QueryComponentRemoteService(null);

expect(service.query({})).rejects.toThrow();
await expect(service.query({})).rejects.toThrow();

});

Expand Down

0 comments on commit d590a3b

Please sign in to comment.