From 886111b21a7c6c722e615b6928e055b4bfb1acb6 Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Fri, 15 May 2026 12:20:27 +0200 Subject: [PATCH] test(useDelayedLoading): lock in custom threshold parameter behavior --- .../hooks/__tests__/useDelayedLoading.test.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/web/src/hooks/__tests__/useDelayedLoading.test.ts b/packages/web/src/hooks/__tests__/useDelayedLoading.test.ts index 20a04267..42d7efc0 100644 --- a/packages/web/src/hooks/__tests__/useDelayedLoading.test.ts +++ b/packages/web/src/hooks/__tests__/useDelayedLoading.test.ts @@ -139,4 +139,26 @@ describe('useDelayedLoading', () => { // the 300 ms minDisplay floor. The skeleton should be hidden by now. expect(result.current).toBe(false); }); + + it('honors a custom threshold passed via options', () => { + const { result } = renderHook( + ({ loading }) => useDelayedLoading(loading, { threshold: 50 }), + { initialProps: { loading: true } }, + ); + expect(result.current).toBe(false); + act(() => { vi.advanceTimersByTime(49); }); + expect(result.current).toBe(false); + act(() => { vi.advanceTimersByTime(1); }); + expect(result.current).toBe(true); + }); + + it('default 200ms threshold does not fire at t=50ms (negative control for the custom-threshold test above)', () => { + // Negative control: same conditions with the default would still be false at t=50. + const { result: defaultThresholdResult } = renderHook( + ({ loading }) => useDelayedLoading(loading), + { initialProps: { loading: true } }, + ); + act(() => { vi.advanceTimersByTime(50); }); + expect(defaultThresholdResult.current).toBe(false); + }); });