generated from Team-INSERT/Repository-generator-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from Team-INSERT/test/useInfiniteScroll
useInfiniteScroll 테스트코드 작성
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |