Skip to content

Commit

Permalink
Merge pull request #166 from Team-INSERT/test/useInfiniteScroll
Browse files Browse the repository at this point in the history
useInfiniteScroll 테스트코드 작성
  • Loading branch information
jyh071116 authored Jan 18, 2024
2 parents c9ed9fd + d2d77b6 commit 30c733a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/hooks/useInfiniteScroll.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { fireEvent, renderHook } from "@testing-library/react";
import useInfiniteScroll from "./useInfiniteScroll";

describe("useInfiniteScroll", () => {
it("스크롤을 끝까지 내렸을 때 fetchNextPage 호출 확인", () => {
const fetchNextPage = jest.fn();
renderHook(() => useInfiniteScroll(fetchNextPage));

Object.defineProperty(window, "scrollY", {
value: 0,
});
Object.defineProperty(document.documentElement, "offsetHeight", {
value: 3000,
});
// 스크롤을 끝까지 내리지 않음
fireEvent.scroll(window);
// 스크롤을 끝까지 내림
window.scrollY = 3000;
fireEvent.scroll(window);

expect(fetchNextPage).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 30c733a

Please sign in to comment.