Skip to content

Commit 9975ecf

Browse files
committed
test: cover null sentinel guard in useInfiniteScroll
1 parent 8401116 commit 9975ecf

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/__tests__/useInfiniteScroll.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ describe('useInfiniteScroll hook', () => {
154154
expect(rootMargin).toBe('0px 0px 20% 0px');
155155
});
156156

157+
it('does not create an observer when sentinel ref is not attached', () => {
158+
function NoRefWrapper(props: UseInfiniteScrollOptions) {
159+
useInfiniteScroll(props);
160+
return <div />;
161+
}
162+
render(<NoRefWrapper next={jest.fn()} hasMore={true} dataLength={5} />);
163+
expect(MockIntersectionObserver.instances).toHaveLength(0);
164+
});
165+
157166
it('does not throw when IntersectionObserver is unavailable (SSR)', () => {
158167
const g = globalThis as Record<string, unknown>;
159168
const original = g['IntersectionObserver'];

0 commit comments

Comments
 (0)