Skip to main content
Unit testing helps catch bugs early and ensures your components work as expected. This guide covers Jest configuration, testing React components, and testing Expo modules.

Setup

Install Dependencies

Configure Jest

1

Create Jest config

jest.config.js
2

Create setup file

jest-setup.js
3

Add test script

package.json

Testing Components

Basic Component Test

app/components/__tests__/Button.test.tsx

Component with State

app/components/__tests__/Counter.test.tsx

Async Components

app/components/__tests__/UserProfile.test.tsx

Testing Hooks

app/hooks/__tests__/useCounter.test.ts

Testing Expo Router

Test navigation and routing with Expo Router’s testing utilities.

Setup Router Tests

app/(tabs)/__tests__/layout.test.tsx

Testing Navigation

app/__tests__/navigation.test.tsx

Testing Native Modules

Mock Native Modules

__tests__/camera.test.tsx

Testing Expo Modules

modules/__tests__/MyModule.test.ts

Snapshot Testing

Component Snapshots

app/components/__tests__/Card.test.tsx

Updating Snapshots

Test Coverage

Generate Coverage Report

Coverage Configuration

jest.config.js

CI/CD Integration

GitHub Actions

.github/workflows/test.yml

Best Practices

1. Use Test IDs

2. Test User Behavior, Not Implementation

3. Arrange-Act-Assert Pattern

4. Clean Up After Tests

Troubleshooting

Tests Timeout

Mock Not Working

Act Warnings

Next Steps

E2E Testing

Test full user workflows

Testing Router

Test Expo Router navigation

CI/CD

Automate testing in CI

Error Handling

Test error scenarios