Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com>
  • Loading branch information
dominik-zeglen and krzysztofwolski authored Jul 6, 2020
1 parent b1ac074 commit 77d5ab4
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/containers/BackgroundTasks/BackgroundTasksProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,24 @@ describe("Background task provider", () => {
it("can queue multiple tasks", done => {
let cycle = 0;

const tasks: TaskData[] = [
{
// during 2 cycle it should be complete
const shortTask = {
handle: jest.fn(() =>
Promise.resolve(cycle > 1 ? TaskStatus.SUCCESS : TaskStatus.PENDING)
),
onCompleted: jest.fn()
},
{
};

// long task will be completed after 3 cicle
const longTask = {
handle: jest.fn(() =>
Promise.resolve(cycle > 2 ? TaskStatus.SUCCESS : TaskStatus.PENDING)
),
onCompleted: jest.fn()
}
};
const tasks: TaskData[] = [
shortTask,
longTask
];

const { result } = renderBackgroundTasks();
Expand All @@ -167,10 +172,10 @@ describe("Background task provider", () => {
jest.advanceTimersByTime(backgroundTasksRefreshTime);

setImmediate(() => {
expect(tasks[0].handle).toHaveBeenCalledTimes(2);
expect(tasks[1].handle).toHaveBeenCalledTimes(2);
expect(tasks[0].onCompleted).toHaveBeenCalledTimes(1);
expect(tasks[1].onCompleted).toHaveBeenCalledTimes(0);
expect(shortTask.handle).toHaveBeenCalledTimes(2);
expect(longTask.handle).toHaveBeenCalledTimes(2);
expect(shortTask.onCompleted).toHaveBeenCalledTimes(1);
expect(longTask.onCompleted).toHaveBeenCalledTimes(0);

// Set time to backgroundTasksRefreshTime * 3
cycle += 1;
Expand Down

0 comments on commit 77d5ab4

Please sign in to comment.