A Jest preset to painlessly test your Expo / React Native apps.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Jest Expo provides multiple preset configurations to support testing across different platforms and scenarios. Each preset extends React Native's base Jest preset with Expo-specific configurations, module mappings, and platform-specific settings.
The main Jest preset that extends React Native's Jest preset with Expo-specific configurations.
// In package.json or jest.config.js
{
"jest": {
"preset": "jest-expo"
}
}Features:
react-native/jest-presetreact-native-vector-icons to @expo/vector-iconsUsage Example:
// jest.config.js
module.exports = {
preset: "jest-expo",
// Additional configuration can be added here
};Multi-platform testing configuration that runs tests across iOS, Android, web, and Node.js environments simultaneously.
// In package.json or jest.config.js
{
"jest": {
"preset": "jest-expo/universal"
}
}Features:
Usage Example:
// Running tests with universal preset
npm test
// Tests will run on all platforms: iOS, Android, web, Node.jsIndividual presets for testing on specific platforms with optimized configurations.
// In package.json or jest.config.js
{
"jest": {
"preset": "jest-expo/ios"
}
}Features:
.ios.snap files)// In package.json or jest.config.js
{
"jest": {
"preset": "jest-expo/android"
}
}Features:
.android.snap files)// In package.json or jest.config.js
{
"jest": {
"preset": "jest-expo/web"
}
}Features:
.web.snap files)// In package.json or jest.config.js
{
"jest": {
"preset": "jest-expo/node"
}
}Features:
.node.snap files)Platform presets can be customized using configuration functions:
/**
* Generate platform-specific Jest configuration
* @param displayOptions - Display options for the preset
* @param extensions - File extensions to handle
* @param platform - Target platform name
* @param options - Additional preset options
* @returns Complete Jest configuration object
*/
function getPlatformPreset(
displayOptions?: DisplayOptions,
extensions?: string[],
platform?: string,
options?: PresetOptions
): JestConfig;
interface DisplayOptions {
name?: string;
color?: string;
}
interface PresetOptions {
setupFilesAfterEnv?: string[];
testEnvironment?: string;
snapshotResolver?: string;
}Usage Example:
// jest.config.js
const { getWebPreset } = require("jest-expo/config");
module.exports = getWebPreset({
name: "Custom Web Tests",
color: "blue"
});All presets include comprehensive asset file handling for Expo and Metro asset types:
// Supported asset extensions
const supportedAssets = [
// Images: bmp, gif, jpg, jpeg, png, psd, svg, webp, xml, heic, avif
// Videos: m4v, mov, mp4, mpeg, mpg, webm
// Audio: aac, aiff, caf, m4a, mp3, wav
// Documents: html, pdf, yaml, yml
// Fonts: otf, ttf
// Archives: zip
// Databases: db
];All presets include Expo-specific module name mappings:
// Automatic module mappings
const moduleNameMapper = {
"^react-native-vector-icons$": "@expo/vector-icons",
"^react-native-vector-icons/(.*)": "@expo/vector-icons/$1",
};Optimized transform ignore patterns for Expo and React Native ecosystem:
const transformIgnorePatterns = [
"/node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)",
"/node_modules/react-native-reanimated/plugin/"
];