fix(test): type MetricsBar's useAsync mock against the real hook shape (Closes #429) - #437
Merged
Jagadeeshftw merged 1 commit intoAug 29, 2026
Conversation
Closes AnchorNet-Org#429) MetricsBar.test.tsx mocked useAsync with only { state, refresh }, omitting reload and mutate, so tsc reported TS2345 at all four call sites and the component was verified against a contract the real hook never returns. Replace the hand-written mocks with a typed mockUseAsync factory whose return type is ReturnType<typeof useAsync>; a future change to the hook's shape now breaks compilation instead of silently testing a fabricated interface. No as any, @ts-expect-error or Partial cast used. MetricsBar itself only consumes state and refresh (reload/mutate are intentionally unused: the manual refresh must stay silent, which is refresh's contract), so no behavioural gap was found. Repo-wide tsc error count drops from 9 to 5; the remaining 5 are the out-of-scope SettlementTable.test.tsx errors. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
Jagadeeshftw
added a commit
that referenced
this pull request
Aug 29, 2026
* Fix CI typecheck blindspot Closes #425 * test: use semantic settlement table queries (#439) Co-authored-by: Jagadeeshftw <92681651+Jagadeeshftw@users.noreply.github.com> * feat(a11y): add jest-axe and jsx-a11y with baseline for SettlementTable and MetricsBar (#438) * fix(test): type MetricsBar's useAsync mock against the real hook shape (Closes #429) (#437) MetricsBar.test.tsx mocked useAsync with only { state, refresh }, omitting reload and mutate, so tsc reported TS2345 at all four call sites and the component was verified against a contract the real hook never returns. Replace the hand-written mocks with a typed mockUseAsync factory whose return type is ReturnType<typeof useAsync>; a future change to the hook's shape now breaks compilation instead of silently testing a fabricated interface. No as any, @ts-expect-error or Partial cast used. MetricsBar itself only consumes state and refresh (reload/mutate are intentionally unused: the manual refresh must stay silent, which is refresh's contract), so no behavioural gap was found. Repo-wide tsc error count drops from 9 to 5; the remaining 5 are the out-of-scope SettlementTable.test.tsx errors. Generated with Codebuff 🤖 Co-authored-by: Codebuff <noreply@codebuff.com> * fix(api): enforce idempotent retries and classified failure handling (#436) * fix(api): enforce bounded idempotent retries Retry only explicitly idempotent operations for transient failures, preserve abort propagation through response consumption, and expose deterministic attempt and elapsed-time bounds. Cover the status allowlist, jittered backoff, timeout handling, abort races, and non-idempotent exclusions with fake-timer tests. * fix(ui): integrate API error taxonomy Route classified API failures through the existing reporter and toast infrastructure, suppress deliberate aborts, and preserve actionable inline states. Document the pre-change audit, defects, retry rationale, elapsed ceiling, coverage, and baseline constraints. * test: add tests for lib/wallet.ts (#435) Closes #<n>. ### Coverage Inventory * **wallet.ts exports**: `saveAccount`, `loadAccount`, `clearAccount`, `truncateAddress`, `mockAddress`, `STORAGE_KEY`. * **useWallet.test.ts**: Covers *none* of the above. It only tests the `useWallet` hook to ensure it throws when used outside a `WalletProvider`. ### The Defect (Mocking Strategy & Incorrect Assumptions) The issue description assumed that `wallet.ts` implements a real wallet integration with error paths like "Provider absent", "User rejection", and "Chain mismatch". However, as documented in `wallet.ts`, this module is purely a mock / stand-in that stores a deterministic fake address in `localStorage`. Since the module does not integrate with any real wallet provider (like Freighter), these assumed error paths and listeners **do not exist** in `wallet.ts`. I have reported these "untested paths" as `.todo()` in the test suite to formally acknowledge them as defects (i.e. the promised feature doesn't exist). I have written tests for the actual exposed methods, verifying: - Successful saving, loading, and clearing of accounts from `localStorage` - The `loadAccount` error paths (invalid JSON, missing address, regex validation failure) - Address truncation formatting - Deterministic seed generation in `mockAddress` --------- Co-authored-by: daveedAJ <davidadegoke055@gmail.com> Co-authored-by: Jagadeeshftw <92681651+Jagadeeshftw@users.noreply.github.com> Co-authored-by: Opulence Chuks <162402876+Opulencechuks@users.noreply.github.com> Co-authored-by: Annie <168873935+AnnieIj@users.noreply.github.com> Co-authored-by: Codebuff <noreply@codebuff.com> Co-authored-by: Luis Carlos Fuentes De Avila <125478683+Flames4fun@users.noreply.github.com> Co-authored-by: ugoocreates-pixel <ugoocreates@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #429 by making
MetricsBar.test.tsxmockuseAsyncagainst the hook's real return type instead of a fabricated{ state, refresh }shape.The four errors before (and the repo-wide count)
npx tsc --noEmitreported 9error TSlines onmain:src/components/MetricsBar.test.tsx(21,41),(34,41),(47,41),(64,41)—TS2345: ... is missing the following properties from type ...: reload, mutatesrc/components/SettlementTable.test.tsx(72,19),(269,21),(270,21),(271,21),(272,21)— out of scope per the issueAfter this PR: 5 errors (repo-wide count drops by exactly 4), and
grep MetricsBaron the tsc output is empty. The remaining 5 are the out-of-scopeSettlementTable.test.tsxerrors.Which hook members MetricsBar actually uses
Only
stateandrefresh.src/components/MetricsBar.tsxdestructures exactly those two (const { state, refresh } = useAsync(load)). The manual "Refresh" button callsrefresh(), and the auto-refresh interval drivesrefreshviauseInterval.Mock-factory decision
Added an in-file
mockUseAsync(overrides)factory whose return type isReturnType<typeof useAsync>— i.e. the full four-member contract (state,reload,refresh,mutate) — with no-op defaults and per-test overrides:as any,@ts-expect-error, orPartial<>cast on the mock was used. ThePartial<UseAsyncResult>is only the override input to the factory; the factory always returns the complete, fully-typed result.useAsync; if that changes, it should be promoted to a shared test util.Behavioural gap
None found.
reload/mutateare legitimately unused byMetricsBar: a manual reload must stay silent (existing data stays visible, per the test suite's contract), which is exactlyrefresh's job —reload()would flash the loading skeleton, andmutateis for optimistic local updates this component doesn't do. The mock now includes them as no-ops so the component is tested against the contract it actually receives.Assertion changes
None. Two mock-honesty cleanups only (no assertion semantics changed):
mockReloadlocal tomockRefresh(it was always passed asrefresh).pendingSettlementsto the ready-state mock data so it matches the realMetricsshape the component consumes.Notes
mainwas ~a month behind the org repo, so the branch was rebased onto the org's currentmain(feb9b67) before fixing; the diff contains onlyMetricsBar.test.tsx.tsc --noEmitstep (the add a typecheck #418 "add a typecheck" change was reverted to unblock merge); this drift was invisible for that reason. This PR fixes the drift itself; a CI typecheck gate remains the separate tracked issue.useAsync's own tests are a separate issue; the factory here pins the four-member contract (state,reload,refresh,mutate) those tests should assert.Checklist
CHANGELOG.mdentry under the next## [x.y.z]section(see the Format note at the top of
CHANGELOG.md), or this PRis docs-only / test-only / internal tooling and doesn't change
user-facing behavior. — test-only, no entry needed per the changelog's own note.
Closes #429