Skip to content

test: Add comprehensive unit tests for React hooks and stores#40

Open
AugistineCreates wants to merge 1 commit into
LabsCrypt:mainfrom
AugistineCreates:feat/add-unit-tests
Open

test: Add comprehensive unit tests for React hooks and stores#40
AugistineCreates wants to merge 1 commit into
LabsCrypt:mainfrom
AugistineCreates:feat/add-unit-tests

Conversation

@AugistineCreates

Copy link
Copy Markdown

This pr closes #6

This PR introduces comprehensive unit tests for core React hooks and custom stores to improve test coverage and ensure stability.

Changes Made

  • Configured TypeScript Jest transformations and coverage settings in jest.config.js.
  • Added a Node-based execution path for Jest tests in package.json.
  • Added comprehensive test suites for:
    • useApi
    • useContractMutation
    • useConfirmedMutation
    • useTransactionPreview
    • useRepaymentOperation
    • useWalletStore
  • Created standard React Query test utilities (test-utils.ts).

@ogazboiz ogazboiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

appreciate the effort on test coverage, but this can't land as-is, it regresses the suite from 1 failing test to 12 failed suites / 49 failed tests. the jest config changes are the core problem:

  1. jest.config.js:10 replaces testEnvironment: "jest-environment-jsdom" with a hand-rolled transform, so every DOM test loses jsdom and now fails with "document is not defined" (Button.test.tsx, AmountInput.test.tsx, RemittanceForm.test.tsx, ErrorBoundary.test.tsx, useModalFocusTrap.test.tsx, stores.test.ts). keep testEnvironment: "jest-environment-jsdom" and drop the custom transform (next/jest already provides one).
  2. jest.config.js:10 transform regex '^.+\.(ts|tsx)$' has doubled backslashes so it never matches .ts/.tsx. remove the transform line entirely.
  3. @testing-library/react-hooks is imported by useConfirmedMutation.test.ts:2, useContractMutation.test.ts, useRepaymentOperation.test.ts:2, useTransactionPreview.test.ts but it's not in package.json and is deprecated/react-19-incompatible. rewrite those to use renderHook/act from @testing-library/react (already a dep).
  4. useTransactionPreview.test.ts and useContractMutation.test.ts are syntactically corrupted (quotes replaced by backslashes). rewrite the imports/string literals with proper quotes.
  5. jest.config.js:17-24 adds a coverageThreshold 75/80 that fails the run regardless (actual ~37%). drop it (or set to current) on a test-adding PR.
  6. test-utils.ts uses cacheTime (TanStack v5 renamed it gcTime).

the two files that DO run and assert real behavior (useWalletStore.test.ts, useApi.test.ts) are a good base. get the config + the broken files sorted so the suite runs green and i'll take another pass.

if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

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.

[Testing] Unit-test the data and contract hooks and stores, wire a coverage gate

2 participants