Registry / testing / jest-expo

jest-expo

JSON →
library55.0.16jsnpmunverified

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.

npm install jest-expo
INSTALL
IMPORT
SIG · JEST-EXPO
J
jest-expo
testingjavascriptv55.0.16
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Jest Preset Configuration
{ "jest": { "preset": "jest-expo" } }
import jestExpo from 'jest-expo'; // jest-expo is primarily a preset string for configuration, not a runtime import
The most common usage is to specify 'jest-expo' as the preset string in your package.json or jest.config.js.
Platform-Specific Presets
{ "jest": { "projects": ["jest-expo/ios", "jest-expo/web"] } }
import { iosPreset } from 'jest-expo'; // Not exposed as direct imports, use string paths in config
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.
Jest Configuration Types (TypeScript)
import type { Config } from '@jest/types';
import { Config } from '@jest/types';
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.

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.

{ "name": "my-expo-app", "version": "1.0.0", "main": "expo-router/entry", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", "test": "jest" }, "jest": { "preset": "jest-expo", "transformIgnorePatterns": [ "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)" ] }, "dependencies": { "expo": "^55.0.0", "expo-status-bar": "~1.2.0", "expo-router": "~3.4.0", "react": "19.0.0-rc-34e8f7a6f-20240905", "react-native": "0.83.0", "react-native-safe-area-context": "4.10.1", "react-native-screens": "3.31.1", "react-server-dom-webpack": "~19.0.4 || ~19.1.5 || ~19.2.4" }, "devDependencies": { "@babel/core": "^7.20.0", "jest": "^29.2.1", "jest-expo": "^55.0.0", "@testing-library/react-native": "^12.0.0" }, "private": true } // __tests__/App.test.tsx import React from 'react'; import { render, screen } from '@testing-library/react-native'; import App from '../App'; describe('<App />', () => { it('renders correctly', () => { render(<App />); expect(screen.getByText('Open up App.js to start working on your app!')).toBeTruthy(); }); it('has a default welcome message', () => { render(<App />); expect(screen.getByText(/Open up App.js to start working on your app!/i)).toBeOnTheScreen(); }); });
Debug
Known issues
breakingExpo SDK 55, and consequently jest-expo v55, officially drops support for the Legacy Architecture. Projects must migrate to the New Architecture.
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.
affects: >=55.0.0
gotchaJest 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.
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(), }));`.
affects: >=32.0.0
gotchaConfiguring `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`.
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.
affects: >=32.0.0
deprecatedThe `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.
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.
affects: All versions
gotchaJest'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.
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.
affects: All versions
breakingSecurity 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.
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.
affects: >=53.0.13 <55.0.16 (for SDK 53/54), >=55.0.0-canary (for SDK 55)
Errors
Common errors & fixes
Cannot find native module 'ExpoSomething'
Jest runs in a Node.js environment and does not have access to Expo or React Native's native modules.
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`.
Jest encountered an unexpected token
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.
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.
SyntaxError: Cannot use import statement outside a module
You are trying to import an ES Module in a CommonJS context or Jest's environment is not configured to handle ES Modules correctly.
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`.
TypeError: createCacheKeyFunction is not a function
This error occurred in older versions of `jest-expo` (around SDK 43) due to an incompatibility with Jest internals.
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.
Couldn't find a navigation object. Is your component inside NavigationContainer?
Your component uses hooks or components from `@react-navigation` but is being tested outside of a `NavigationContainer` context.
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.
Upgrade
Version history
55.0.16latest on npm
Audit
Dependencies
exporequiredCore dependency for Expo SDK functionality.
react-nativerequiredCore dependency for React Native functionality.
react-server-dom-webpackrequiredRequired for React Server Components support, primarily to address security vulnerabilities and ensure compatibility with React 19.
Agent activity
4 hits · last 30 days
node
4
Resources