Skip to content

Commit

Permalink
test: add utility method times to reduce repeating
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Dec 27, 2021
1 parent 92f83ec commit 4e3e39f
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/github-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import {

const body = 'mock-comment-body';

function times(count: number) {
return function wrapper(method: () => void) {
Array(Math.floor(count))
.fill(null)
.forEach(() => method());
};
}

describe('github-client', () => {
beforeEach(() => {
onIssueCreated.mockClear();
Expand Down Expand Up @@ -44,11 +52,7 @@ describe('github-client', () => {

test('should recover from 5x API errors', async () => {
// Request should fail 5 times
mockApiError.mockReturnValueOnce(true);
mockApiError.mockReturnValueOnce(true);
mockApiError.mockReturnValueOnce(true);
mockApiError.mockReturnValueOnce(true);
mockApiError.mockReturnValueOnce(true);
times(5)(() => mockApiError.mockReturnValueOnce(true));

mockNoExistingIssues.mockReturnValueOnce(true);

Expand All @@ -65,13 +69,7 @@ describe('github-client', () => {
});

test('should fail request after 6x failures', async () => {
mockApiError.mockReturnValueOnce(true);
mockApiError.mockReturnValueOnce(true);
mockApiError.mockReturnValueOnce(true);
mockApiError.mockReturnValueOnce(true);
mockApiError.mockReturnValueOnce(true);
mockApiError.mockReturnValueOnce(true);

times(6)(() => mockApiError.mockReturnValueOnce(true));
mockNoExistingIssues.mockReturnValueOnce(true);

await expect(
Expand Down

0 comments on commit 4e3e39f

Please sign in to comment.