test: add hook test coverage (Tier 3)#417
Merged
gabitoesmiapodo merged 3 commits intotest/utilsfrom Mar 25, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
5 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Adds new unit test coverage for key web3/token hooks to validate behavior across connection state, token list processing, and ERC-20 balance querying.
Changes:
- Add
useWeb3Status/useWeb3StatusConnectedtests with module-level wagmi mocks. - Add
useTokenListstests covering deduplication, native token injection, and schema filtering via mockeduseSuspenseQueries. - Add
useErc20Balancetests using a mockedpublicClient.readContractand a real TanStack Query client.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/hooks/useWeb3Status.test.ts | New tests for aggregated wagmi-derived web3 status + connected-only contract. |
| src/hooks/useTokenLists.test.ts | New tests for token list combination behavior (dedupe, native token injection, invalid token filtering). |
| src/hooks/useErc20Balance.test.ts | New tests for ERC-20 balance query behavior (enabled gating, success/error paths). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2eaabf8 to
beabdaf
Compare
8c31105 to
5ce7095
Compare
5ce7095 to
8ddaae3
Compare
beabdaf to
ba75a54
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8ddaae3 to
33e3ca3
Compare
ba75a54 to
1fcbe2f
Compare
- useWeb3Status.test.ts: 8 tests covering disconnected/connected state, isWalletSynced, switchingChain, disconnect, switchChain, appChainId - useWeb3StatusConnected.test.ts: 2 tests (co-located in same file) covering throw-on-disconnect and pass-through when connected - useErc20Balance.test.ts: 5 tests covering missing address/token, native token skip, successful balance fetch, and error handling - useTokenLists.test.ts: 4 tests covering return shape, deduplication, native token injection, and schema validation filtering
- Add beforeEach mock clearing in useWeb3Status to prevent shared mock call history leaking between tests - Switch mockReturnValue to mockReturnValueOnce for the connected test in useWeb3StatusConnected (hook calls useWeb3Status twice internally) - Add beforeEach mockReadContract.mockClear() in useErc20Balance to prevent cross-test false negatives on not.toHaveBeenCalled assertions
1fcbe2f to
d6ced76
Compare
fernandomg
approved these changes
Mar 25, 2026
src/hooks/useWeb3Status.test.ts
Outdated
|
|
||
| it('returns connected state with wallet address', () => { | ||
| const mock = { | ||
| address: '0xabc123' as `0x${string}`, |
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
useWeb3Statuscovering all wagmi hook aggregation pathsuseWeb3StatusConnectedthrow/pass contractuseTokenListsdeduplication and native token injection logicuseErc20Balancewith mocked publicClient and tanstack queryTest plan
pnpm testpasses on this branchvi.mock('wagmi', ...)