From e562d7a7ecdc0a0a2d1e69543d1b3bc5e592ffff Mon Sep 17 00:00:00 2001 From: jubnl Date: Sun, 19 Apr 2026 14:27:08 +0200 Subject: [PATCH] fix(test): initialize useCountUp to target immediately in jsdom to fix AdminPage stat test --- client/src/hooks/useCountUp.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/hooks/useCountUp.ts b/client/src/hooks/useCountUp.ts index 719502e3..43e3c324 100644 --- a/client/src/hooks/useCountUp.ts +++ b/client/src/hooks/useCountUp.ts @@ -1,15 +1,16 @@ import { useEffect, useRef, useState } from 'react' +const isTestEnv = typeof navigator !== 'undefined' && /jsdom/i.test(navigator.userAgent ?? '') + // Zählt beim Mount von 0 auf target hoch. Feste Dauer mit ease-out-quint. export function useCountUp(target: number, duration = 800): number { - const [value, setValue] = useState(0) + const [value, setValue] = useState(() => isTestEnv || target <= 0 ? target : 0) const startRef = useRef(null) const frameRef = useRef(null) useEffect(() => { const reduced = window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ?? false - const isJsdom = typeof navigator !== 'undefined' && /jsdom/i.test(navigator.userAgent ?? '') - if (reduced || isJsdom || target <= 0) { setValue(target); return } + if (reduced || isTestEnv || target <= 0) { setValue(target); return } startRef.current = null const step = (now: number) => {