Jest

React Native 7 min min read Updated: Aug 03, 2026 Beginner
Jest
Beginner Topic 5 of 15

Jest

Jest is the default JavaScript testing framework included with React Native, used for writing and running unit and integration tests for your application logic and components.

Jest is Pre-configured

New React Native projects come with Jest already configured, including a jest.config.js file and a preset specifically designed for React Native’s environment.

Writing a Basic Test

javascript // sum.test.js function sum(a, b) { return a + b; } test('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3); });

Running Tests

bash npx jest

Using describe Blocks

javascript describe('formatCurrency', () => { test('formats whole numbers correctly', () => { expect(formatCurrency(100)).toBe('$100.00'); }); test('formats decimals correctly', () => { expect(formatCurrency(99.5)).toBe('$99.50'); }); });

Mocking Functions and Modules

javascript jest.mock('../services/api'); import { fetchUsers } from '../services/api'; fetchUsers.mockResolvedValue([{ id: 1, name: 'John' }]);

Testing Asynchronous Code

javascript test('fetches user data', async () => { const data = await fetchUserData(1); expect(data.name).toBe('John'); });

Generating Coverage Reports

bash npx jest --coverage

Conclusion

Jest provides a robust, pre-configured foundation for writing unit and integration tests in React Native applications, forming the basis for the more specialized testing tools covered later in this section.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators