Skip to content

test: add hook test coverage (Tier 3)#417

Merged
gabitoesmiapodo merged 3 commits intotest/utilsfrom
test/hooks
Mar 25, 2026
Merged

test: add hook test coverage (Tier 3)#417
gabitoesmiapodo merged 3 commits intotest/utilsfrom
test/hooks

Conversation

@gabitoesmiapodo
Copy link
Collaborator

Summary

  • Adds tests for useWeb3Status covering all wagmi hook aggregation paths
  • Adds tests for useWeb3StatusConnected throw/pass contract
  • Adds tests for useTokenLists deduplication and native token injection logic
  • Adds tests for useErc20Balance with mocked publicClient and tanstack query

Test plan

  • pnpm test passes on this branch
  • All wagmi hooks mocked at module level with vi.mock('wagmi', ...)
  • No real network calls; all async paths covered via mock resolution

Copilot AI review requested due to automatic review settings March 23, 2026 21:18
@vercel
Copy link

vercel bot commented Mar 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
components.dappbooster Ready Ready Preview, Comment Mar 25, 2026 6:47pm
demo.dappbooster Ready Ready Preview Mar 25, 2026 6:47pm
docs.dappbooster Ready Ready Preview, Comment Mar 25, 2026 6:47pm

Request Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / useWeb3StatusConnected tests with module-level wagmi mocks.
  • Add useTokenLists tests covering deduplication, native token injection, and schema filtering via mocked useSuspenseQueries.
  • Add useErc20Balance tests using a mocked publicClient.readContract and 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

- 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

it('returns connected state with wallet address', () => {
const mock = {
address: '0xabc123' as `0x${string}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit picking, 0x${string} is exported as Address from viem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5861213. Replaced 0x${string} casts with the Address type imported from viem.

Base automatically changed from test/enhance-existing to test/utils March 25, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants