Unit & Component Testing
This page documents how the dapp’s unit tests and component tests are structured, what they focus on, and how to extend them.
The goal of this layer is to make business rules, state transitions, and wallet UX behaviour explicit and stable, without pulling in full backend or blockchain infrastructure.
This page assumes you are familiar with basic Vitest and React Testing Library usage.
It focuses on project-specific patterns rather than generic testing tutorials.
Overview
Overview
Unit and component tests in the dapp primarily live in:
- chatModeStore.test.ts
At this layer we:
- Test Zustand stores directly via their public API (no DOM).
- Test React components via React Testing Library and DOM assertions.
- Mock external dependencies (wagmi, Next.js primitives, Prisma, network calls) so tests are fast, deterministic, and side‑effect free.
Common tools used here:
- Vitest (
describe,it,expect,vi). - React Testing Library (
render,fireEvent,act, and queries likegetByText). @testing-library/jest-domfor expressive DOM matchers.happy-domas the test environment (set invitest.config.ts).
Other suites that live at this layer
Beyond the flagship wallet header components, Vitest also owns:
- Wallet utilities:
RateLimitModal,ProcessingModal,ConnectWrapper,DisconnectButton,OpenWalletButton,NetworkWidget, and their supporting hooks (testfiles undercomponents/utilities/wallet/__tests__) which cover timer-driven transitions, wagmi hook stubs, and mobile fallbacks. - Mint & swap experiences: Integration suites for
app/mint(page wrapper, TokenStatus, NFTScreen, ButtonSection) andapp/swap/components/SwapClientassert page wiring, JSON-LD injection, wagmi + NFT store interactions, and gate-specific button states. - Docs/SEO pages: Lightweight page tests (
app/api-docs/page.test.tsx,app/terms/terms.integration.test.tsx,app/terms/page.unit.test.ts,app/swap/page.integration.test.tsx,app/metadata.unit.test.ts) that ensure JSON-LD helpers, metadata exports, and headline structure stay consistent when content shifts.
Summary
- Zustand stores are tested as pure state containers: focus on initial state, transitions, and immutability.
- Wallet components are tested via React Testing Library with wagmi mocks, ensuring UX stays stable across refactors.
- Global helpers in
test/setup.ts,test/utils/wagmi.tsx, andtest/helpers/env.tsprovide a consistent, controlled environment so individual test files can stay focused on behaviour.
Use this page as a reference when adding or updating unit and component tests; for API routes and OpenAPI contracts, see the other testing subpages.