or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdindex.mdpresets.mdrsc.mdtesting-utilities.md
tile.json

tessl/npm-jest-expo

A Jest preset to painlessly test your Expo / React Native apps.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/jest-expo@54.0.x

To install, run

npx @tessl/cli install tessl/npm-jest-expo@54.0.0

index.mddocs/

Jest Expo

Jest Expo provides a comprehensive Jest testing preset specifically designed for Expo and React Native applications, enabling seamless testing across multiple platforms including iOS, Android, web, and Node.js environments. It extends React Native's Jest preset with Expo-specific configurations, module name mappings, custom transform patterns for asset files, and platform-specific test execution capabilities.

Package Information

  • Package Name: jest-expo
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install jest-expo

Core Imports

// Main testing utilities
import { mockProperty, unmockProperty, unmockAllProperties, mockLinking } from "jest-expo";

For CommonJS:

const { mockProperty, unmockProperty, unmockAllProperties, mockLinking } = require("jest-expo");

Basic Usage

Using the Main Preset

Configure Jest in your package.json or jest.config.js:

{
  "jest": {
    "preset": "jest-expo"
  }
}

Jest Binary Proxy

Jest Expo provides a Jest binary proxy (bin/jest) that ensures consistent Jest execution across different package managers. The proxy forwards all arguments and stdio streams to the actual Jest binary, solving issues where package managers don't hoist binaries from nested dependencies:

# Run tests using the jest-expo binary proxy
npx jest

# Or if configured in package.json scripts:
npm test

# The proxy supports all Jest CLI arguments
npx jest --watch --coverage

Features:

  • Automatically locates and executes the correct Jest binary
  • Forwards all command-line arguments to Jest
  • Maintains the same exit codes and signals as Jest
  • Works consistently across npm, yarn, and other package managers

Platform-Specific Testing

{
  "jest": {
    "preset": "jest-expo/universal"
  }
}

Basic Testing Example

import { mockProperty, unmockProperty } from "jest-expo";

describe("My Component", () => {
  beforeEach(() => {
    // Mock a property for testing
    mockProperty(console, "warn", jest.fn());
  });

  afterEach(() => {
    // Restore original property
    unmockProperty(console, "warn");
  });

  test("should work correctly", () => {
    // Your test code here
  });
});

Architecture

Jest Expo is built around several key components:

  • Base Preset: Main Jest configuration extending React Native's preset with Expo-specific module mappings and transforms
  • Platform Presets: Specialized configurations for iOS, Android, web, and Node.js environments
  • Universal Preset: Multi-platform testing that runs tests across all supported platforms
  • RSC Support: React Server Components testing capabilities for modern React patterns
  • Testing Utilities: Property mocking and React Native API mocking utilities
  • Asset Handling: Custom transformers for images, fonts, and other asset types

Capabilities

Jest Presets

Core Jest preset configurations for different platforms and testing scenarios. Includes base preset with Expo-specific module mappings and platform-specific presets for targeted testing.

// Available preset configurations (configured in package.json or jest.config.js)
"jest-expo"              // Base preset with Expo configurations
"jest-expo/universal"    // Multi-platform testing preset
"jest-expo/ios"          // iOS-specific testing preset
"jest-expo/android"      // Android-specific testing preset
"jest-expo/web"          // Web-specific testing preset
"jest-expo/node"         // Node.js/SSR testing preset

Jest Presets

Testing Utilities

Property mocking utilities for controlling object properties during tests, and React Native Linking API mocking for navigation testing.

function mockProperty<T>(object: T, property: keyof T, mockValue: any): void;
function unmockProperty<T>(object: T, property: keyof T): void;
function unmockAllProperties(): void;
function mockLinking(): (eventName: string, eventData: any) => void;

Testing Utilities

React Server Components (RSC)

Advanced testing support for React Server Components, including RSC-specific presets and custom Jest matchers for flight data validation.

// RSC preset configurations
"jest-expo/rsc"          // RSC universal preset
"jest-expo/rsc/ios"      // RSC iOS preset
"jest-expo/rsc/android"  // RSC Android preset
"jest-expo/rsc/web"      // RSC web preset

// RSC Jest matchers
interface JestExpoMatchers<R> {
  toMatchFlight(expectedFlight: string): R;
  toMatchFlightSnapshot(): R;
}

React Server Components

Configuration

Advanced configuration utilities for customizing Jest presets and watch plugins for enhanced development experience.

// Configuration functions (from jest-expo/config)
function getWebPreset(options?: PresetOptions): JestConfig;
function getIOSPreset(options?: PresetOptions): JestConfig;
function getAndroidPreset(options?: PresetOptions): JestConfig;
function getNodePreset(options?: PresetOptions): JestConfig;
function getPlatformPreset(displayOptions?: DisplayOptions, extensions?: string[], platform?: string, options?: { isServer?: boolean; isReactServer?: boolean }): JestConfig;
function withWatchPlugins(jestConfig: JestConfig): JestConfig;
function getWatchPlugins(jestConfig: JestConfig): WatchPlugin[];

Configuration

Types

interface JestExpoMatchers<R> extends Record<string, any> {
  toMatchFlight(expectedFlight: string): R;
  toMatchFlightSnapshot(): R;
}

interface PresetOptions {
  displayOptions?: DisplayOptions;
  extensions?: string[];
  platform?: string;
}

interface DisplayOptions {
  name?: string;
  color?: string;
}