This document describes the testing setup for the WalletConnect AppKit React Native project.
To avoid duplication and ensure consistency across packages, we use a shared Jest setup approach:
jest-shared-setup.ts: Contains common mocks used across all packages- Package-specific
jest-setup.tsfiles: Import the shared setup and add package-specific mocks
- The root
jest.config.tsdefines a moduleNameMapper that maps@shared-jest-setupto the shared setup file:
moduleNameMapper: {
'^@shared-jest-setup$': '<rootDir>/jest-shared-setup.ts'
}- Each package's
jest.config.tsoverrides this mapping to use a relative path:
moduleNameMapper: {
'^@shared-jest-setup$': '../../jest-shared-setup.ts'
}- Each package has its own
jest-setup.tsfile that imports the shared setup and only adds package-specific mocks:
// Import shared setup
import '@shared-jest-setup';
// Import helper functions from shared setup (if needed)
import { mockThemeContext, mockUseTheme } from '@shared-jest-setup';
// Apply package-specific mocks
mockThemeContext('../src/context/ThemeContext');
mockUseTheme('../src/hooks/useTheme');
// Add any other package-specific mocks here if neededThe shared setup includes mocks for:
@react-native-async-storage/async-storage- React Native components and APIs (StyleSheet, Dimensions, Platform, etc.)
react-native-svgcomponents- Helper functions for mocking package-specific modules
All common mocks are centralized in the shared setup file, eliminating duplication across packages. This makes the testing setup more maintainable and consistent.
To add a new mock that should be shared across packages:
- Add it to
jest-shared-setup.ts - If it's a function that needs to be imported by packages, export it from
jest-shared-setup.ts
For package-specific mocks, add them to the package's jest-setup.ts file.
Each package includes a type declaration file for the shared setup module:
// types/shared-jest-setup.d.ts
declare module '@shared-jest-setup' {
export function mockThemeContext(modulePath: string): void;
export function mockUseTheme(modulePath: string): void;
}To run tests for all packages:
yarn testTo run tests for a specific package:
yarn workspace @reown/appkit-[package-name]-react-native testEnd-to-end tests run against the example app's web build (Expo web) using Playwright. They run in CI via .github/workflows/e2e.yml.
- Tests:
apps/native/tests/*.spec.ts(shared helpers inapps/native/tests/shared/) - Config:
apps/native/playwright.config.ts
From the repo root:
yarn playwright:test # runs all e2e specs (via apps/native)Or from apps/native:
yarn playwright:install # install the chromium browser (first time)
yarn playwright test tests/wallet.spec.ts # run a single spec
yarn playwright test --debug # step through with the Playwright InspectorAn HTML report is written to apps/native/playwright-report/; open it with yarn playwright show-report.
For more information, refer to the Playwright documentation.