From 7fb7bdc0c857edd5fbdcc7deafa8634ebc0868a3 Mon Sep 17 00:00:00 2001 From: jyh071116 Date: Thu, 11 Jan 2024 15:30:29 +0900 Subject: [PATCH 1/3] =?UTF-8?q?test(useInfiniteScroll):=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A1=A4=EC=9D=84=20=EB=81=9D=EA=B9=8C=EC=A7=80=20?= =?UTF-8?q?=EB=82=B4=EB=A0=B8=EC=9D=84=20=EB=95=8C=20fetchNextPage=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useInfiniteScroll.spec.tsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/hooks/useInfiniteScroll.spec.tsx diff --git a/src/hooks/useInfiniteScroll.spec.tsx b/src/hooks/useInfiniteScroll.spec.tsx new file mode 100644 index 00000000..9f5d55c6 --- /dev/null +++ b/src/hooks/useInfiniteScroll.spec.tsx @@ -0,0 +1,25 @@ +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", { + writable: true, + configurable: true, + value: 0, + }); + Object.defineProperty(document.documentElement, "offsetHeight", { + writable: true, + configurable: true, + value: 3000, + }); + + window.scrollY = 3000; + + fireEvent.scroll(window); + expect(fetchNextPage).toHaveBeenCalled(); + }); +}); From 07d7a7a6b3ad182e42c436e44a07c3465e8ae1f2 Mon Sep 17 00:00:00 2001 From: jyh071116 Date: Thu, 11 Jan 2024 15:32:49 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test(useInfiniteScroll):=20=EC=93=B8?= =?UTF-8?q?=EB=AA=A8=EC=97=86=EB=8A=94=20=ED=94=84=EB=A1=9C=ED=8D=BC?= =?UTF-8?q?=ED=8B=B0=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useInfiniteScroll.spec.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/hooks/useInfiniteScroll.spec.tsx b/src/hooks/useInfiniteScroll.spec.tsx index 9f5d55c6..8945f792 100644 --- a/src/hooks/useInfiniteScroll.spec.tsx +++ b/src/hooks/useInfiniteScroll.spec.tsx @@ -7,13 +7,9 @@ describe("useInfiniteScroll", () => { renderHook(() => useInfiniteScroll(fetchNextPage)); Object.defineProperty(window, "scrollY", { - writable: true, - configurable: true, value: 0, }); Object.defineProperty(document.documentElement, "offsetHeight", { - writable: true, - configurable: true, value: 3000, }); From d2d77b6a4eeae04a6f940eddf864ce036f9e391a Mon Sep 17 00:00:00 2001 From: jyh071116 Date: Thu, 11 Jan 2024 15:38:47 +0900 Subject: [PATCH 3/3] =?UTF-8?q?test(useInfiniteScroll):=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A1=A4=EC=9D=84=20=EB=81=9D=EA=B9=8C=EC=A7=80=20?= =?UTF-8?q?=EB=82=B4=EB=A6=AC=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EC=99=80=20=EC=8A=A4=ED=81=AC=EB=A1=A4=EC=9D=84=20?= =?UTF-8?q?=EB=81=9D=EA=B9=8C=EC=A7=80=20=EB=82=B4=EB=A6=B0=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useInfiniteScroll.spec.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hooks/useInfiniteScroll.spec.tsx b/src/hooks/useInfiniteScroll.spec.tsx index 8945f792..a4a0b01c 100644 --- a/src/hooks/useInfiniteScroll.spec.tsx +++ b/src/hooks/useInfiniteScroll.spec.tsx @@ -12,10 +12,12 @@ describe("useInfiniteScroll", () => { Object.defineProperty(document.documentElement, "offsetHeight", { value: 3000, }); - + // 스크롤을 끝까지 내리지 않음 + fireEvent.scroll(window); + // 스크롤을 끝까지 내림 window.scrollY = 3000; - fireEvent.scroll(window); - expect(fetchNextPage).toHaveBeenCalled(); + + expect(fetchNextPage).toHaveBeenCalledTimes(1); }); });