diff --git a/src/api/__tests__/FileVersionAPI-test.js b/src/api/__tests__/FileVersionAPI-test.js index 2100d82d6..931c05685 100644 --- a/src/api/__tests__/FileVersionAPI-test.js +++ b/src/api/__tests__/FileVersionAPI-test.js @@ -55,34 +55,37 @@ describe('api/FileVersionAPI', () => { describe('successHandler()', () => { beforeEach(() => { - api.fetchFromMarker = jest.fn(); + api.fetchFromMarker = jest.fn().mockReturnValue(Promise.resolve()); api.emit = jest.fn(); }); it('should call fetch the remaining annotations if the version has more to fetch', () => { api.data = { entries: [{}] }; - api.successHandler({ entries: [{}, {}], next_marker: 'marker', limit: 1 }); - expect(api.data.entries.length).toEqual(3); - expect(api.fetchFromMarker).toBeCalled(); + api.successHandler({ entries: [{}, {}], next_marker: 'marker', limit: 1 }).then(() => { + expect(api.data.entries.length).toEqual(3); + expect(api.fetchFromMarker).toBeCalled(); + }); }); it('should not call fetch if no more annotations need to be fetched', () => { api.data = { entries: [{}] }; - api.successHandler({ entries: [{}, {}], limit: 1 }); - expect(api.data.entries.length).toEqual(3); - expect(api.fetchFromMarker).not.toBeCalled(); + api.successHandler({ entries: [{}, {}], limit: 1 }).then(() => { + expect(api.data.entries.length).toEqual(3); + expect(api.fetchFromMarker).not.toBeCalled(); + }); }); it('should emit an error if the success response is of type error', () => { api.fileVersionId = 123; - api.successHandler({ type: 'error' }); - const error = new Error(`Could not read annotations from file version with ID ${api.fileVersionId}`); + api.successHandler({ type: 'error' }).catch(() => { + const error = new Error(`Could not read annotations from file version with ID ${api.fileVersionId}`); - expect(api.data.entries.length).toEqual(1); - expect(api.fetchFromMarker).not.toBeCalled(); - expect(api.emit).toBeCalledWith(ANNOTATOR_EVENT.error, { - reason: ERROR_TYPE.read, - error: error.toString() + expect(api.data.entries.length).toEqual(1); + expect(api.fetchFromMarker).not.toBeCalled(); + expect(api.emit).toBeCalledWith(ANNOTATOR_EVENT.error, { + reason: ERROR_TYPE.read, + error: error.toString() + }); }); }); });