useBountyStatus.test.tsx tests a hook that no longer exists: it mocks fetchBounty, asserts data with enabled:false, and leaks the module-level poller registry between cases
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 57/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- react, typescript
Direzione di ricerca
Start with src/hooks/useBountyStatus.test.tsx, then read src/hooks/useBountyStatus.ts and src/hooks/bountyPoller.ts to align tests with the hook’s subscription registry. Run npx jest src/hooks/useBountyStatus.test.tsx to confirm the failures; done means the suite isolates registry state and covers the stated subscription, polling, refetch, and failed-fetch behavior. The issue also raises whether to remove or reconnect useSmartPolling, which adds scope.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Location
src/hooks/useBountyStatus.test.tsx (whole file), against the current src/hooks/useBountyStatus.ts and src/hooks/bountyPoller.ts.
Problem
The suite was written for the pre-#631 hook, which ran its own useSmartPolling loop over an injected fetchBounty. Its own header still says so: "Covers the hook wrapping useSmartPolling". The hook is now a thin useSyncExternalStore over the module-level registry in bountyPoller.ts. The tests were never updated, and several of them cannot pass against the current implementation:
-
enabled: falsecases assert fetched data. Cases 1 and 2 render withenabled: false. In the current hook that makes the subscribe function a no-op (useBountyStatus.ts:42), sosubscribeBountyis never called, no entry is created, andgetBountySnapshotreturns{ bounty: null, source: null, loading: false, error: null }. The assertionsexpect(result.current.bounty).toEqual(mockBounty)andexpect(result.current.source).toBe("live")are asserting state that the code has no way to produce. -
Case 3 asserts a callback the hook never invokes.
onStatusChangeis destructured and then never referenced anywhere inuseBountyStatus.ts(filed separately), soexpect(onStatusChange).toHaveBeenCalledWith("open")can only time out. -
Cross-test state leakage.
registryinbountyPoller.tsis module-level and is never reset.beforeEach(() => jest.clearAllMocks())clears thefetchBountymock but not the registry, so an entry created by one case — along with itsbounty, itssourceand, if the terminal-status branch did not fire, its livesetInterval— survives into the next. Cases therefore pass or fail depending on declaration order, and the real intervals keep firing across the file. -
The mock is now at the wrong seam.
jest.mock("@/lib/api", () => ({ fetchBounty: jest.fn() }))replaces the module the registry calls, not anything the hook calls. That is why the suite looks like it is exercising fetch behaviour while actually exercising nothing: the hook under test makes no API call of its own, and the mock also strips every other export of@/lib/api, so any future import from that module inside the hook silently becomesundefined.
Relatedly, useSmartPolling is now dead code: the only references to it anywhere under src/ outside its own file are its own test (src/hooks/useSmartPolling.test.tsx) and a comment in useClaimRace.ts. Nothing renders it. The open report #568 ("useSmartPolling stops polling after the first re-render because useBountyStatus passes inline fetchFn/compareFn/onDataChange") describes a call site that no longer exists, so that issue is unverifiable as written and should be re-scoped or closed.
Why it matters
This is worse than having no tests, which is the state #620 was filed about. The file's presence is what makes useBountyStatus look covered, so the genuine defects now living in bountyPoller.ts (a stopped poller that never restarts, a failed fetch blanking the bounty, refetch being a no-op) sit behind a green-looking test file that exercises none of them. And because the suite cannot pass as written, CI is either red on this file or the file is being skipped — both of which hide the same thing.
Reproduction
npx jest src/hooks/useBountyStatus.test.tsx — cases 1, 2 and 3 fail for the reasons above (1 and 2 on the bounty/source assertion, 3 on the waitFor timeout).
Suggested fix
Rewrite the suite against the seam the hook actually has:
- Export a
__resetBountyPollerRegistry()(test-only) frombountyPoller.ts, or clear the map viajest.resetModules()inbeforeEach, so each case starts clean. - Mock
@/lib/apiwith...jest.requireActual("@/lib/api")spread in, overriding onlyfetchBounty, so the rest of the module stays intact. - Use fake timers and assert the behaviours that matter: one shared fetch loop for two subscribers on the same id; polling stops on a terminal status; polling restarts when a new subscriber arrives after the last one left;
refetch()performs a fetch while the loop is stopped; a failed fetch surfaceserrorwithout blanking a previously loadedbounty. - Drop the
enabled: falsedata assertions, and replace them with the real contract:enabled: falsemeans no subscription and no fetch.
Then decide useSmartPolling's fate: delete the hook and its test if the registry is the way forward, or re-wire it and keep its tests meaningful. Leaving it in src/hooks/ invites a contributor to adopt it and inherit the bugs reported against it.
- Lingua principale
- TypeScript
- Stelle
- 1
- Fork
- 94
- Merge medio
- 1h 2m
- PR unite (30g)
- 25
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MergeFi/frontend
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
accessibility bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
MergeFi/frontend#835 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di MergeFi/frontend
Issue simili
-
ログイン中の404画面にヘッダーとナビを出すApertaCodex使用可 コード
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ryuki-moro/Nicomaru#218 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
sveltejs/svelte-eslint-parser#1008 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
silverbucket/inbox-rs#351 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: The H2 series' and the H3C's fan 3 is labelled "Chamber Fan", Bambu calls it the exhaust fanApertaarea:ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
bug front P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
invoicerr-app/invoicerr#964 ·
I maintainer di solito rispondono entro 1 giorno