# Unit Testing Setup ## Installation ```bash yarn add -D jest @testing-library/react-native @testing-library/jest-native ``` ## Jest Configuration **jest.config.js:** ```javascript module.exports = { preset: 'react-native', setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'], transformIgnorePatterns: [ 'node_modules/(?!(react-native|@react-native|react-navigation)/)', ], collectCoverageFrom: [ 'src/**/*.{ts,tsx}', '!src/**/*.d.ts', '!src/**/*.stories.{ts,tsx}', ], coverageThreshold: { global: { branches: 80, functions: 80, lines: 80, statements: 80, }, }, }; ``` ## Test Setup ```typescript // src/__tests__/setup.ts import 'react-native-gesture-handler/jestSetup'; jest.mock('react-native-reanimated', () => { const Reanimated = require('react-native-reanimated/mock'); Reanimated.default.call = () => {}; return Reanimated; }); jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); // Mock AsyncStorage jest.mock('@react-native-async-storage/async-storage', () => require('@react-native-async-storage/async-storage/jest/async-storage-mock') ); // Mock react-native-config jest.mock('react-native-config', () => ({ API_BASE_URL: 'https://test-api.example.com', APP_ENV: 'test', })); ``` ## Component Testing ```typescript // src/components/Button/__tests__/Button.test.tsx import React from 'react'; import {render, fireEvent} from '@testing-library/react-native'; import {Button} from '../Button'; describe('Button Component', () => { it('renders correctly', () => { const {getByText} = render(