Skip to content

Commit

Permalink
test(@toss/react): useInterval hook test, changed to English, improve…
Browse files Browse the repository at this point in the history
…d scope (#433)

* test(@toss/react): rewrite useInterval test code in english

* test(@toss/react): improve useInterval hook test coverage
  • Loading branch information
Gaic4o authored Mar 22, 2024
1 parent 566384d commit d012c13
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/react/react/src/hooks/useInterval.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useInterval } from './useInterval';
jest.useFakeTimers();

describe('useInterval', () => {
it('정해진 시간이 지날때마다, 콜백을 실행한다', () => {
it('Should execute a callback every time a set time passes.', () => {
const callback = jest.fn();

renderHook(() =>
Expand All @@ -26,7 +26,7 @@ describe('useInterval', () => {
expect(callback).toBeCalledTimes(2);
});

it('number option도 동일하게실행한다', () => {
it('should work the same with number options as well.', () => {
const callback = jest.fn();

renderHook(() => useInterval(callback, 3000));
Expand All @@ -43,4 +43,22 @@ describe('useInterval', () => {

expect(callback).toBeCalledTimes(2);
});

it('Should not set the interval when delay is null.', () => {
const callback = jest.fn();

renderHook(() => useInterval(callback, { delay: null }));

jest.advanceTimersByTime(3000);

expect(callback).not.toBeCalled();
});

it('Should execute the callback immediately when the trailing option is false.', () => {
const callback = jest.fn();

renderHook(() => useInterval(callback, { delay: 3000, trailing: false }));

expect(callback).toBeCalledTimes(1);
});
});

0 comments on commit d012c13

Please sign in to comment.