Test Configuration
Rainbow’s Jest configuration is defined injest.config.js:
Running Tests
Run All Tests
Run Specific Test
Run Tests in Watch Mode
Run Tests with Coverage
Test Organization
Tests are located in__tests__ directories adjacent to the code they test:
Writing Tests
Basic Test Structure
Testing Utility Functions
Example fromsrc/utils/__tests__/search.test.ts:
Testing React Components
Testing Custom Hooks
Testing Zustand Stores
Example fromsrc/state/internal/queryStore/tests/queryStore.test.ts:
Test Coverage Guidelines
What to Test
Utility Functions
All utility functions should have comprehensive unit tests covering:
- Happy path (expected inputs)
- Edge cases (empty strings, nulls, undefined)
- Error conditions
Business Logic
Core business logic should be thoroughly tested:
- Token calculations
- Price conversions
- Transaction parsing
- Wallet operations
State Management
Store creators and state updates:
- Initial state
- State mutations
- Derived state
- Persistence
What Not to Test
- Simple presentational components without logic
- Third-party library internals
- Configuration files
- Type definitions alone
Mocking
Mocking Modules
Mocking React Native Modules
Mocking MMKV Storage
Testing Async Code
Using async/await
Using waitFor
Using Promises
Best Practices
Use Descriptive Test Names
Good:Arrange-Act-Assert Pattern
Test One Thing Per Test
Good:Clean Up After Tests
Avoid Testing Implementation Details
Test behavior, not implementation: Good:Verification Checklist
Before submitting a PR with tests:Common Issues
Tests Timeout
Increase timeout for slow async operations:Tests Are Flaky
Ensure proper cleanup and avoid race conditions:Mock Not Working
Ensure mocks are defined before imports:Additional Resources
Jest Documentation
Official Jest testing framework docs
React Native Testing Library
Testing utilities for React Native
Testing Best Practices
Common testing mistakes to avoid
Code Conventions
Review coding standards