test: add useApi hook tests for loading/ok/error/null/refetch/cancel#316
Closed
shinzoxD wants to merge 2 commits into
Closed
test: add useApi hook tests for loading/ok/error/null/refetch/cancel#316shinzoxD wants to merge 2 commits into
shinzoxD wants to merge 2 commits into
Conversation
…discriminated-union State<T> + refetch type caused TS2339 errors\nin pairs/Client.tsx and stats/Client.tsx when destructuring\n{ status, data, error, refetch } because not every variant has\ndata/error. Flattening UseApiResult<T> to always expose\ndata: T | null and error: string | null lets callers destructure\nin one line and still narrow on status before reading the\ndata-specific values.\n\nAlso adds && data / && status.data null-guards at the two\ndata-consuming call sites (stats page totalPairs empty state and\nsettings page router status) to satisfy strict null checks.
Author
|
@mikewheeleer — friendly ping on this fork PR (test: add useApi hook tests for loading/ok/error/null/refetch/cancel).\n\nCI is currently failing on pre-existing main-branch test flakes ( |
Contributor
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.
Summary
Adds a focused
useApitest covering the five behaviours the hook is designed to provide:loadingand resolves tookwith the resolved dataerrorwith the rejected error'smessagepathisnull— noapiGetcall, no state transitionrefetch()triggers a newapiGetcallWhy
useApiis the foundation for dashboard fetching but is untested, so the cancellation guard (thecancelledflag in the effect) and thenullshort-circuit are unverified. This locks both branches down so future refactors of the hook are safe.Test Plan
npx jest src/lib/__tests__/useApi— 5/5 pass../apiClientso the hook is tested in isolationrenderHook+waitFor+actfrom@testing-library/react(already in devDeps)Linked issue
Closes #299
Payout wallet (Stellar):
GBVHELLD2JE235Y2NGTDT3MWI3T65ON6SY4N6FBHYVDAQ5FZC2CP5QXHGrantFox OSS campaign — smart escrow payout on merge.