or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

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

index.mddocs/

0

# Jest Expo

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: jest-expo

7

- **Package Type**: npm

8

- **Language**: JavaScript/TypeScript

9

- **Installation**: `npm install jest-expo`

10

11

## Core Imports

12

13

```javascript

14

// Main testing utilities

15

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

16

```

17

18

For CommonJS:

19

20

```javascript

21

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

22

```

23

24

## Basic Usage

25

26

### Using the Main Preset

27

28

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

29

30

```json

31

{

32

"jest": {

33

"preset": "jest-expo"

34

}

35

}

36

```

37

38

### Jest Binary Proxy

39

40

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:

41

42

```bash

43

# Run tests using the jest-expo binary proxy

44

npx jest

45

46

# Or if configured in package.json scripts:

47

npm test

48

49

# The proxy supports all Jest CLI arguments

50

npx jest --watch --coverage

51

```

52

53

**Features:**

54

- Automatically locates and executes the correct Jest binary

55

- Forwards all command-line arguments to Jest

56

- Maintains the same exit codes and signals as Jest

57

- Works consistently across npm, yarn, and other package managers

58

59

### Platform-Specific Testing

60

61

```json

62

{

63

"jest": {

64

"preset": "jest-expo/universal"

65

}

66

}

67

```

68

69

### Basic Testing Example

70

71

```javascript

72

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

73

74

describe("My Component", () => {

75

beforeEach(() => {

76

// Mock a property for testing

77

mockProperty(console, "warn", jest.fn());

78

});

79

80

afterEach(() => {

81

// Restore original property

82

unmockProperty(console, "warn");

83

});

84

85

test("should work correctly", () => {

86

// Your test code here

87

});

88

});

89

```

90

91

## Architecture

92

93

Jest Expo is built around several key components:

94

95

- **Base Preset**: Main Jest configuration extending React Native's preset with Expo-specific module mappings and transforms

96

- **Platform Presets**: Specialized configurations for iOS, Android, web, and Node.js environments

97

- **Universal Preset**: Multi-platform testing that runs tests across all supported platforms

98

- **RSC Support**: React Server Components testing capabilities for modern React patterns

99

- **Testing Utilities**: Property mocking and React Native API mocking utilities

100

- **Asset Handling**: Custom transformers for images, fonts, and other asset types

101

102

## Capabilities

103

104

### Jest Presets

105

106

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.

107

108

```javascript { .api }

109

// Available preset configurations (configured in package.json or jest.config.js)

110

"jest-expo" // Base preset with Expo configurations

111

"jest-expo/universal" // Multi-platform testing preset

112

"jest-expo/ios" // iOS-specific testing preset

113

"jest-expo/android" // Android-specific testing preset

114

"jest-expo/web" // Web-specific testing preset

115

"jest-expo/node" // Node.js/SSR testing preset

116

```

117

118

[Jest Presets](./presets.md)

119

120

### Testing Utilities

121

122

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

123

124

```javascript { .api }

125

function mockProperty<T>(object: T, property: keyof T, mockValue: any): void;

126

function unmockProperty<T>(object: T, property: keyof T): void;

127

function unmockAllProperties(): void;

128

function mockLinking(): (eventName: string, eventData: any) => void;

129

```

130

131

[Testing Utilities](./testing-utilities.md)

132

133

### React Server Components (RSC)

134

135

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

136

137

```javascript { .api }

138

// RSC preset configurations

139

"jest-expo/rsc" // RSC universal preset

140

"jest-expo/rsc/ios" // RSC iOS preset

141

"jest-expo/rsc/android" // RSC Android preset

142

"jest-expo/rsc/web" // RSC web preset

143

144

// RSC Jest matchers

145

interface JestExpoMatchers<R> {

146

toMatchFlight(expectedFlight: string): R;

147

toMatchFlightSnapshot(): R;

148

}

149

```

150

151

[React Server Components](./rsc.md)

152

153

### Configuration

154

155

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

156

157

```javascript { .api }

158

// Configuration functions (from jest-expo/config)

159

function getWebPreset(options?: PresetOptions): JestConfig;

160

function getIOSPreset(options?: PresetOptions): JestConfig;

161

function getAndroidPreset(options?: PresetOptions): JestConfig;

162

function getNodePreset(options?: PresetOptions): JestConfig;

163

function getPlatformPreset(displayOptions?: DisplayOptions, extensions?: string[], platform?: string, options?: { isServer?: boolean; isReactServer?: boolean }): JestConfig;

164

function withWatchPlugins(jestConfig: JestConfig): JestConfig;

165

function getWatchPlugins(jestConfig: JestConfig): WatchPlugin[];

166

```

167

168

[Configuration](./configuration.md)

169

170

## Types

171

172

```typescript { .api }

173

interface JestExpoMatchers<R> extends Record<string, any> {

174

toMatchFlight(expectedFlight: string): R;

175

toMatchFlightSnapshot(): R;

176

}

177

178

interface PresetOptions {

179

displayOptions?: DisplayOptions;

180

extensions?: string[];

181

platform?: string;

182

}

183

184

interface DisplayOptions {

185

name?: string;

186

color?: string;

187

}

188

```