Fixed test throwing unhandled promise

This commit is contained in:
Alejandro Celaya
2019-10-05 19:31:47 +02:00
parent c9df044e1a
commit a7613435ea

View File

@@ -36,6 +36,12 @@ describe('selectedServerReducer', () => {
const apiClientMock = { const apiClientMock = {
health: jest.fn().mockResolvedValue({ version }), health: jest.fn().mockResolvedValue({ version }),
}; };
const buildApiClient = jest.fn().mockResolvedValue(apiClientMock);
beforeEach(() => {
apiClientMock.health.mockClear();
buildApiClient.mockClear();
});
afterEach(() => { afterEach(() => {
ServersServiceMock.findServerById.mockClear(); ServersServiceMock.findServerById.mockClear();
@@ -48,17 +54,18 @@ describe('selectedServerReducer', () => {
version, version,
}; };
await selectServer(ServersServiceMock, async () => apiClientMock)(serverId)(dispatch); await selectServer(ServersServiceMock, buildApiClient)(serverId)(dispatch);
expect(dispatch).toHaveBeenCalledTimes(2); expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: RESET_SHORT_URL_PARAMS }); expect(dispatch).toHaveBeenNthCalledWith(1, { type: RESET_SHORT_URL_PARAMS });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SELECT_SERVER, selectedServer: expectedSelectedServer }); expect(dispatch).toHaveBeenNthCalledWith(2, { type: SELECT_SERVER, selectedServer: expectedSelectedServer });
}); });
it('invokes dependencies', () => { it('invokes dependencies', async () => {
selectServer(ServersServiceMock)(serverId)(() => {}); await selectServer(ServersServiceMock, buildApiClient)(serverId)(() => {});
expect(ServersServiceMock.findServerById).toHaveBeenCalledTimes(1); expect(ServersServiceMock.findServerById).toHaveBeenCalledTimes(1);
expect(buildApiClient).toHaveBeenCalledTimes(1);
}); });
}); });
}); });