Skip to content

Commit

Permalink
test(api-core): update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob McGuinness committed Jan 31, 2018
1 parent cf4ce9b commit df77ca1
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/api-core/src/tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,21 +553,27 @@ describe('AvApi', () => {
expect(afterResponse).toBeCalledWith(testResponse);
});

test('should request when polling', async () => {
test('should request when polling', () => {
const mockAfterResponse = 'after';
const mockConfig = {
testVal: 'test',
};

await api.onResponse({ config: mockConfig }, mockAfterResponse);
expect(api.config).toHaveBeenCalledWith(mockConfig);
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(setTimeout.mock.calls[0][1]).toBe(testInterval);
expect(api.request).toHaveBeenCalledWith(
expectedNewConfig,
mockAfterResponse
);
const output = api
.onResponse({ config: mockConfig }, mockAfterResponse)
.then(() => {
expect(api.config).toHaveBeenCalledWith(mockConfig);
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(setTimeout.mock.calls[0][1]).toBe(testInterval);
expect(api.request).toHaveBeenCalledWith(
expectedNewConfig,
mockAfterResponse
);
return true;
});

jest.runAllTimers();
return output;
});
});

Expand Down Expand Up @@ -595,7 +601,7 @@ describe('AvApi', () => {

test('should catch error in http, returning undefined if no error.response', async () => {
mockHttp.mockImplementationOnce(() => Promise.reject(new Error('err')));
const response = api.request({});
const response = await api.request({});
expect(response).toBeUndefined();
});

Expand Down

0 comments on commit df77ca1

Please sign in to comment.