Skip to content

Commit

Permalink
test: event es emmited before the promise fails
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanVicens committed Feb 20, 2024
1 parent 0e9b312 commit 7f9a197
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ describe('Environment Content File Downloader', () => {

await downloader.download(file);

expect(handler.mock.calls).toEqual([[25], [50], [75]]);
const firstArgumentsOfProgress = handler.mock.calls.map(
(args) => args[0]
);

expect(firstArgumentsOfProgress).toEqual(
expect.arrayContaining([25, 50, 75])
);
});

it('emits an event when there is an error', async () => {
Expand All @@ -78,5 +84,24 @@ describe('Environment Content File Downloader', () => {
// no-op
});
});

it('emits an event before the promises fails', async () => {
const errorMsg = 'Error uploading file';
const strategy = createDownloadStrategy((callbacks) => {
callbacks.finishedCallback(
{ message: errorMsg } as unknown as Error,
Readable.from('')
);
});

const downloader = new EnvironmentContentFileDownloader(strategy, bucket);

const errorCallback = jest.fn();
downloader.on('error', errorCallback);

await downloader.download(file).catch(() => {
expect(errorCallback).toBeCalled();
});
});
});
});

0 comments on commit 7f9a197

Please sign in to comment.