Testing Guide
Overview
This project uses Jest and React Testing Library for comprehensive unit and integration testing.
Running Tests
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverageTest Structure
__tests__/
├── api/
│ └── chat/
│ └── route.test.js # API route tests
├── app/
│ └── app-page.test.js # App page component tests
├── components/
│ ├── Footer.test.js # Footer component tests
│ ├── Navbar.test.js # Navbar component tests
│ └── WalletProvider.test.js # Wallet provider tests
└── lib/
└── birdeye.test.js # Birdeye utility testsTest Coverage
The test suite covers:
Components: Navbar, Footer, WalletProvider, AppPage
Utilities: Birdeye API integration, address validation, data formatting
API Routes: Chat endpoint with token data fetching
User Interactions: Form submissions, cooldown mechanism, loading states
Writing Tests
Component Tests
API Tests
Mocking
External Dependencies
Next.js: Image, Link components are mocked
Framer Motion: Animations are mocked for testing
Solana Wallet: Wallet adapters are mocked
AI SDK: useChat hook is mocked
Environment Variables
Test environment variables are configured in jest.setup.js:
Best Practices
Descriptive Test Names: Use clear, descriptive test names
Arrange-Act-Assert: Follow the AAA pattern
Test User Behavior: Test from the user's perspective
Mock External Dependencies: Mock API calls and external services
Clean Up: Clear mocks between tests using
jest.clearAllMocks()
Continuous Integration
Tests should run automatically on:
Pull requests
Pushes to main branch
Before deployments
Troubleshooting
Common Issues
Tests failing due to missing mocks:
Ensure all external dependencies are properly mocked in
jest.setup.js
Async tests timing out:
Use
waitForfrom React Testing LibraryIncrease timeout if necessary:
jest.setTimeout(10000)
Component not rendering:
Check that all required props are passed
Verify mocks are correctly configured
Last updated