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 advanced configuration utilities for customizing Jest presets, platform-specific settings, and watch plugins. These utilities enable fine-tuned control over test execution and development workflows.
Functions for generating and customizing platform-specific Jest configurations with advanced options and display settings.
/**
* Generate web-specific Jest configuration
* @param options - Web preset options
* @returns Complete Jest configuration for web testing
*/
function getWebPreset(options?: WebPresetOptions): JestConfig;
interface WebPresetOptions extends PresetOptions {
testEnvironment?: "jsdom";
setupFilesAfterEnv?: string[];
}Features:
.web.snap files)Usage Example:
const { getWebPreset } = require("jest-expo/config");
module.exports = getWebPreset({
displayName: {
name: "Web Tests",
color: "cyan"
},
setupFilesAfterEnv: ["<rootDir>/test-setup-web.js"]
});/**
* Generate iOS-specific Jest configuration
* @param options - iOS preset options
* @returns Complete Jest configuration for iOS testing
*/
function getIOSPreset(options?: IOSPresetOptions): JestConfig;
interface IOSPresetOptions extends PresetOptions {
testEnvironment?: "react-native";
setupFilesAfterEnv?: string[];
}Features:
.ios.snap files)Usage Example:
const { getIOSPreset } = require("jest-expo/config");
module.exports = getIOSPreset({
displayName: {
name: "iOS Tests",
color: "blue"
},
testMatch: ["**/__tests__/**/*.ios.test.js"]
});/**
* Generate Android-specific Jest configuration
* @param options - Android preset options
* @returns Complete Jest configuration for Android testing
*/
function getAndroidPreset(options?: AndroidPresetOptions): JestConfig;
interface AndroidPresetOptions extends PresetOptions {
testEnvironment?: "react-native";
setupFilesAfterEnv?: string[];
}Features:
.android.snap files)Usage Example:
const { getAndroidPreset } = require("jest-expo/config");
module.exports = getAndroidPreset({
displayName: {
name: "Android Tests",
color: "green"
},
testTimeout: 10000
});/**
* Generate Node.js-specific Jest configuration for SSR testing
* @param options - Node preset options
* @returns Complete Jest configuration for Node.js testing
*/
function getNodePreset(options?: NodePresetOptions): JestConfig;
interface NodePresetOptions extends PresetOptions {
testEnvironment?: "node";
setupFilesAfterEnv?: string[];
}Features:
.node.snap files)Usage Example:
const { getNodePreset } = require("jest-expo/config");
module.exports = getNodePreset({
displayName: {
name: "SSR Tests",
color: "yellow"
},
testMatch: ["**/__tests__/**/*.ssr.test.js"]
});Core function for generating any platform-specific Jest configuration with full customization options.
/**
* Generate platform-specific Jest configuration with full customization
* @param displayOptions - Display options for Jest runner
* @param extensions - File extensions to handle
* @param platform - Target platform name
* @param options - Additional preset options including isServer and isReactServer flags
* @returns Complete Jest configuration object
*/
function getPlatformPreset(
displayOptions?: DisplayOptions,
extensions?: string[],
platform?: string,
options?: { isServer?: boolean; isReactServer?: boolean } & PlatformPresetOptions
): JestConfig;
interface DisplayOptions {
name?: string;
color?: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
}
interface PlatformPresetOptions {
testEnvironment?: string;
setupFiles?: string[];
setupFilesAfterEnv?: string[];
snapshotResolver?: string;
testMatch?: string[];
collectCoverageFrom?: string[];
}Usage Example:
const { getPlatformPreset } = require("jest-expo/config");
module.exports = getPlatformPreset(
{ name: "Custom Platform", color: "magenta" },
[".js", ".jsx", ".ts", ".tsx", ".json"],
"custom-platform",
{
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/custom-setup.js"],
testMatch: ["**/__tests__/**/*.custom.test.js"]
}
);Utilities for configuring Jest watch plugins to enhance the development experience with interactive test running.
/**
* Merge custom and default watch plugins with Jest configuration
* @param jestConfig - Base Jest configuration object
* @returns Jest configuration with watch plugins configured
*/
function withWatchPlugins(jestConfig: JestConfig): JestConfig;Features:
jest-watch-select-projects for project selectionjest-watch-typeahead for test name and filename filteringUsage Example:
const { withWatchPlugins } = require("jest-expo/config");
const baseConfig = {
preset: "jest-expo",
projects: [
{ displayName: "iOS", preset: "jest-expo/ios" },
{ displayName: "Android", preset: "jest-expo/android" }
]
};
module.exports = withWatchPlugins(baseConfig);/**
* Generate watch plugin configuration for Jest
* @param jestConfig - Jest configuration object
* @returns Array of watch plugin configurations
*/
function getWatchPlugins(jestConfig: JestConfig): WatchPlugin[];
interface WatchPlugin {
name: string;
config?: Record<string, any>;
}Features:
Usage Example:
const { getWatchPlugins } = require("jest-expo/config");
const jestConfig = {
projects: ["ios", "android", "web"]
};
const watchPlugins = getWatchPlugins(jestConfig);
module.exports = {
...jestConfig,
watchPlugins
};Advanced patterns for configuring multi-platform Jest projects with shared and platform-specific settings.
/**
* Create universal multi-project Jest configuration
* @param projectConfigs - Array of project-specific configurations
* @param globalConfig - Shared configuration for all projects
* @returns Complete multi-project Jest configuration
*/
function createUniversalConfig(
projectConfigs: ProjectConfig[],
globalConfig?: GlobalConfig
): JestConfig;
interface ProjectConfig {
displayName: string | DisplayOptions;
preset?: string;
testMatch?: string[];
setupFilesAfterEnv?: string[];
}
interface GlobalConfig {
collectCoverage?: boolean;
coverageDirectory?: string;
watchPlugins?: WatchPlugin[];
}Usage Example:
const {
getIOSPreset,
getAndroidPreset,
getWebPreset,
withWatchPlugins
} = require("jest-expo/config");
module.exports = withWatchPlugins({
projects: [
getIOSPreset({
displayName: { name: "iOS", color: "blue" },
testMatch: ["**/__tests__/**/*.ios.test.js"]
}),
getAndroidPreset({
displayName: { name: "Android", color: "green" },
testMatch: ["**/__tests__/**/*.android.test.js"]
}),
getWebPreset({
displayName: { name: "Web", color: "cyan" },
testMatch: ["**/__tests__/**/*.web.test.js"]
})
],
collectCoverage: true,
coverageDirectory: "coverage"
});const { getWebPreset, getNodePreset } = require("jest-expo/config");
const isDevelopment = process.env.NODE_ENV === "development";
module.exports = isDevelopment
? getWebPreset({
verbose: true,
watch: true
})
: getNodePreset({
collectCoverage: true,
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
}
});const {
getIOSPreset,
getAndroidPreset,
getWebPreset
} = require("jest-expo/config");
const platforms = process.env.TEST_PLATFORMS?.split(",") || ["ios", "android", "web"];
const projectMap = {
ios: () => getIOSPreset({ displayName: "iOS" }),
android: () => getAndroidPreset({ displayName: "Android" }),
web: () => getWebPreset({ displayName: "Web" })
};
module.exports = {
projects: platforms.map(platform => projectMap[platform]())
};// Configuration function types
declare function getWebPreset(options?: WebPresetOptions): JestConfig;
declare function getIOSPreset(options?: IOSPresetOptions): JestConfig;
declare function getAndroidPreset(options?: AndroidPresetOptions): JestConfig;
declare function getNodePreset(options?: NodePresetOptions): JestConfig;
declare function getPlatformPreset(
displayOptions?: DisplayOptions,
extensions?: string[],
platform?: string,
options?: PlatformPresetOptions
): JestConfig;
declare function withWatchPlugins(jestConfig: JestConfig): JestConfig;
declare function getWatchPlugins(jestConfig: JestConfig): WatchPlugin[];
// Configuration interfaces
interface DisplayOptions {
name?: string;
color?: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
}
interface PresetOptions {
displayName?: string | DisplayOptions;
testEnvironment?: string;
setupFiles?: string[];
setupFilesAfterEnv?: string[];
testMatch?: string[];
collectCoverageFrom?: string[];
coverageThreshold?: CoverageThreshold;
}
interface WebPresetOptions extends PresetOptions {
testEnvironment?: "jsdom";
}
interface IOSPresetOptions extends PresetOptions {
testEnvironment?: "react-native";
}
interface AndroidPresetOptions extends PresetOptions {
testEnvironment?: "react-native";
}
interface NodePresetOptions extends PresetOptions {
testEnvironment?: "node";
}
interface PlatformPresetOptions extends PresetOptions {
snapshotResolver?: string;
isServer?: boolean;
isReactServer?: boolean;
}
interface WatchPlugin {
name: string;
config?: Record<string, any>;
}
interface JestConfig {
preset?: string;
projects?: (string | JestConfig)[];
displayName?: string | DisplayOptions;
testEnvironment?: string;
setupFiles?: string[];
setupFilesAfterEnv?: string[];
testMatch?: string[];
transform?: Record<string, string | [string, any]>;
moduleNameMapper?: Record<string, string>;
snapshotResolver?: string;
watchPlugins?: WatchPlugin[];
collectCoverage?: boolean;
collectCoverageFrom?: string[];
coverageDirectory?: string;
coverageThreshold?: CoverageThreshold;
}
interface CoverageThreshold {
global?: {
branches?: number;
functions?: number;
lines?: number;
statements?: number;
};
}