Skip to content

Commit

Permalink
refactor: 메인 스레드와 독립적인 worker thread의 타이머 로직을 테스트 할 수 없어 타이머 테스트 코드 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgksqkr committed Nov 19, 2024
1 parent 47229a5 commit afd961d
Showing 1 changed file with 0 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { act, renderHook } from '@testing-library/react';

import useTimer from './hooks/useTimer';
import { convertMsecToSecond, formatLeftRoundTime } from './Timer.util';

describe('Timer 테스트', () => {
Expand All @@ -17,56 +14,4 @@ describe('Timer 테스트', () => {
expect(convertedTime).toBe(10);
});
});
describe('Timer 훅 테스트', () => {
jest.useFakeTimers();
const voteMock = jest.fn();
const timeLimit = 10;
const timeLimitMs = timeLimit * 1000;

it('타이머가 종료되었을 때 선택 완료를 누르지 않아도 선택된 옵션이 있으면 투표한다.', () => {
const isSelectedOption = true;
const isVoted = false;

const { result } = renderHook(() =>
useTimer({ timeLimit, isSelectedOption, isVoted, vote: voteMock }),
);

act(() => {
jest.advanceTimersByTime(timeLimitMs);
});

expect(result.current.leftRoundTime).toBe(0);
expect(voteMock).toHaveBeenCalled();
});
it('타이머가 종료되었을 때 이미 투표를 했다면 또 투표를 하지 않는다.', () => {
const isSelectedOption = true;
const isVoted = true;

const { result } = renderHook(() =>
useTimer({ timeLimit, isSelectedOption, isVoted, vote: voteMock }),
);

act(() => {
jest.advanceTimersByTime(timeLimitMs);
});

expect(result.current.leftRoundTime).toBe(0);
expect(voteMock).not.toHaveBeenCalled();
});
it('타이머가 종료되었을 때 선택된 옵션이 없다면 투표되지 않고 기권한다.', () => {
const isSelectedOption = false;
const isVoted = false;

const { result } = renderHook(() =>
useTimer({ timeLimit, isSelectedOption, isVoted, vote: voteMock }),
);

act(() => {
jest.advanceTimersByTime(timeLimitMs);
});

expect(result.current.leftRoundTime).toBe(0);
expect(voteMock).not.toHaveBeenCalled();
});
});
});

0 comments on commit afd961d

Please sign in to comment.