{"id":13372,"library":"jest-expo","title":"Jest Preset for Expo & React Native","description":"jest-expo is a Jest preset designed to streamline the testing process for applications built with Expo and React Native. It handles most of the complex Jest configurations, including mocking native modules from the Expo SDK and React Native environments, enabling developers to focus on writing tests. The current stable version is 55.0.16, aligning with Expo SDK 55. The package follows Expo's release cadence, with major versions tied to SDK releases (typically every few months) and frequent patch updates. Key differentiators include its 'universal' testing capabilities, allowing tests to run and create multi-platform snapshots across iOS, Android, web, and Node.js environments, significantly simplifying cross-platform testing workflows.","status":"active","version":"55.0.16","language":"javascript","source_language":"en","source_url":"git://github.com/expo/expo","tags":["javascript","typescript"],"install":[{"cmd":"npm install jest-expo","lang":"bash","label":"npm"},{"cmd":"yarn add jest-expo","lang":"bash","label":"yarn"},{"cmd":"pnpm add jest-expo","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for Expo SDK functionality.","package":"expo","optional":false},{"reason":"Core dependency for React Native functionality.","package":"react-native","optional":false},{"reason":"Required for React Server Components support, primarily to address security vulnerabilities and ensure compatibility with React 19.","package":"react-server-dom-webpack","optional":false}],"imports":[{"note":"The most common usage is to specify 'jest-expo' as the preset string in your package.json or jest.config.js.","wrong":"import jestExpo from 'jest-expo'; // jest-expo is primarily a preset string for configuration, not a runtime import","symbol":"Jest Preset Configuration","correct":"{ \"jest\": { \"preset\": \"jest-expo\" } }"},{"note":"For granular control over testing environments (e.g., iOS, Android, web, Node.js), specify sub-presets as strings in Jest's `projects` configuration. `jest-expo/universal` runs tests across all supported platforms by default.","wrong":"import { iosPreset } from 'jest-expo'; // Not exposed as direct imports, use string paths in config","symbol":"Platform-Specific Presets","correct":"{ \"jest\": { \"projects\": [\"jest-expo/ios\", \"jest-expo/web\"] } }"},{"note":"When using TypeScript for `jest.config.ts`, import `Config` as a type for robust configuration validation. This isn't a direct import from `jest-expo` but is essential for typed Jest configurations.","wrong":"import { Config } from '@jest/types';","symbol":"Jest Configuration Types (TypeScript)","correct":"import type { Config } from '@jest/types';"}],"quickstart":{"code":"{\n  \"name\": \"my-expo-app\",\n  \"version\": \"1.0.0\",\n  \"main\": \"expo-router/entry\",\n  \"scripts\": {\n    \"start\": \"expo start\",\n    \"android\": \"expo start --android\",\n    \"ios\": \"expo start --ios\",\n    \"web\": \"expo start --web\",\n    \"test\": \"jest\"\n  },\n  \"jest\": {\n    \"preset\": \"jest-expo\",\n    \"transformIgnorePatterns\": [\n      \"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)\"\n    ]\n  },\n  \"dependencies\": {\n    \"expo\": \"^55.0.0\",\n    \"expo-status-bar\": \"~1.2.0\",\n    \"expo-router\": \"~3.4.0\",\n    \"react\": \"19.0.0-rc-34e8f7a6f-20240905\",\n    \"react-native\": \"0.83.0\",\n    \"react-native-safe-area-context\": \"4.10.1\",\n    \"react-native-screens\": \"3.31.1\",\n    \"react-server-dom-webpack\": \"~19.0.4 || ~19.1.5 || ~19.2.4\"\n  },\n  \"devDependencies\": {\n    \"@babel/core\": \"^7.20.0\",\n    \"jest\": \"^29.2.1\",\n    \"jest-expo\": \"^55.0.0\",\n    \"@testing-library/react-native\": \"^12.0.0\"\n  },\n  \"private\": true\n}\n\n// __tests__/App.test.tsx\nimport React from 'react';\nimport { render, screen } from '@testing-library/react-native';\nimport App from '../App';\n\ndescribe('<App />', () => {\n  it('renders correctly', () => {\n    render(<App />);\n    expect(screen.getByText('Open up App.js to start working on your app!')).toBeTruthy();\n  });\n\n  it('has a default welcome message', () => {\n    render(<App />);\n    expect(screen.getByText(/Open up App.js to start working on your app!/i)).toBeOnTheScreen();\n  });\n});\n","lang":"typescript","description":"This quickstart demonstrates how to configure Jest in your package.json using the 'jest-expo' preset and write a basic component test with @testing-library/react-native for an Expo/React Native application."},"warnings":[{"fix":"Ensure your project is configured for React Native's New Architecture. Review Expo's migration guides for SDK 55 to update your project structure and dependencies.","message":"Expo SDK 55, and consequently jest-expo v55, officially drops support for the Legacy Architecture. Projects must migrate to the New Architecture.","severity":"breaking","affected_versions":">=55.0.0"},{"fix":"You must explicitly mock any native modules used by your components in your Jest setup file or directly in tests. For example: `jest.mock('expo-clipboard', () => ({ getStringAsync: jest.fn(), setString: jest.fn(), }));`.","message":"Jest runs in a Node.js environment and cannot directly access native modules (e.g., AsyncStorage, ExpoClipboard, ExpoConstants). This often leads to 'Cannot find native module' errors.","severity":"gotcha","affected_versions":">=32.0.0"},{"fix":"Ensure your `jest.config.js` or `package.json` includes a comprehensive `transformIgnorePatterns` regex that excludes specific problematic packages from being ignored by Babel. The Expo documentation provides a recommended pattern.","message":"Configuring `transformIgnorePatterns` is critical for Jest to correctly transpile modern JavaScript (ESM) and TypeScript used by certain React Native or third-party libraries within `node_modules`.","severity":"gotcha","affected_versions":">=32.0.0"},{"fix":"Migrate your component tests to `@testing-library/react-native`. This library provides a more robust and user-centric approach to testing React Native components.","message":"The `react-test-renderer` library for React Native testing is deprecated. While it may still function, it is not actively maintained and can lead to unexpected issues.","severity":"deprecated","affected_versions":"All versions"},{"fix":"For ESM support, you might need to run Jest with `node --experimental-vm-modules` and potentially configure `transform: {}` or `moduleNameMapper` in your Jest config. Also, ensure your Babel configuration is set up to emit ESM correctly.","message":"Jest's experimental support for ECMAScript Modules (ESM) can lead to 'SyntaxError: Cannot use import statement outside a module' if not configured correctly, especially when `type: 'module'` is set in `package.json` or when importing ESM-only dependencies.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update `jest-expo` to the latest compatible version with your Expo SDK. You may also need to explicitly add `react-server-dom-webpack` to your `package.json:overrides` section to force the correct patched version if using npm.","message":"Security vulnerabilities (CVEs) have been disclosed in `react-server-dom-webpack` (affecting React Server Components). Expo has released patches that restrict `jest-expo`'s peer dependency ranges to compatible `react-server-dom-webpack` versions.","severity":"breaking","affected_versions":">=53.0.13 <55.0.16 (for SDK 53/54), >=55.0.0-canary (for SDK 55)"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Create a Jest setup file (e.g., `jest.setup.js`) and mock the problematic native module. For example: `jest.mock('expo-clipboard', () => ({ getStringAsync: jest.fn(), setString: jest.fn(), }));`. Ensure this setup file is included in your Jest config via `setupFilesAfterEnv`.","cause":"Jest runs in a Node.js environment and does not have access to Expo or React Native's native modules.","error":"Cannot find native module 'ExpoSomething'"},{"fix":"Adjust the `transformIgnorePatterns` in your Jest configuration to ensure the problematic modules are transpiled by Babel. The default `jest-expo` preset includes a robust pattern, but it might need customization for specific libraries.","cause":"Jest's transformer (Babel) is not processing certain files in `node_modules` that use modern JavaScript syntax (e.g., ES modules, TypeScript), leading to syntax errors.","error":"Jest encountered an unexpected token"},{"fix":"If your project uses `type: 'module'` in `package.json` or you have ESM dependencies, configure Jest to run with `--experimental-vm-modules` (e.g., `\"test\": \"node --experimental-vm-modules node_modules/jest/bin/jest.js\"`) and potentially adjust `moduleNameMapper` or `transform` options in `jest.config.js`.","cause":"You are trying to import an ES Module in a CommonJS context or Jest's environment is not configured to handle ES Modules correctly.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Update `jest-expo` to the latest compatible version for your Expo SDK. This was a known issue that was patched in subsequent `jest-expo` releases.","cause":"This error occurred in older versions of `jest-expo` (around SDK 43) due to an incompatibility with Jest internals.","error":"TypeError: createCacheKeyFunction is not a function"},{"fix":"Wrap the component being tested with a mock `NavigationContainer` or mock the `@react-navigation/native` module in your Jest setup to provide dummy navigation context, preventing the runtime error.","cause":"Your component uses hooks or components from `@react-navigation` but is being tested outside of a `NavigationContainer` context.","error":"Couldn't find a navigation object. Is your component inside NavigationContainer?"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}