Skip to content

Commit 03b86a2

Browse files
committed
test/window-scroll 🧊 test: Add test for useWindowScroll
1 parent f16597c commit 03b86a2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { renderHook } from '@testing-library/react';
2+
3+
import { useWindowScroll } from './useWindowScroll';
4+
5+
const mockScrollTo = vi.fn();
6+
7+
beforeAll(() => {
8+
vi.stubGlobal('scrollTo', mockScrollTo);
9+
});
10+
11+
afterAll(() => {
12+
vi.unstubAllGlobals();
13+
});
14+
15+
it('Should use window scroll', () => {
16+
const { result } = renderHook(() => useWindowScroll());
17+
18+
expect(result.current.value).toEqual({ x: 0, y: 0 });
19+
20+
result.current.scrollTo({ x: 100, y: 100 });
21+
22+
expect(globalThis.scrollTo).toBeCalledWith({ left: 100, top: 100, behavior: 'smooth' });
23+
});

0 commit comments

Comments
 (0)