Comprehensive TypeScript type definitions for the Jest testing framework ecosystem providing shared types for configuration, test results, transforms, and global utilities.
npx @tessl/cli install tessl/npm-jest--types@30.0.0Jest Types provides comprehensive TypeScript type definitions for the Jest testing framework ecosystem. It contains shared types used across Jest's internal packages and offers public interfaces for Jest configuration, test results, transforms, circus (Jest's test runner), and global utilities.
npm install @jest/typesimport type { Circus, Config, Global, TestResult, TransformTypes } from "@jest/types";For specific namespace imports:
import type { Config } from "@jest/types";
import type { Global } from "@jest/types";import type { Config, Global } from "@jest/types";
// Define Jest configuration with proper typing
const config: Config.InitialOptions = {
testEnvironment: "node",
collectCoverage: true,
coverageDirectory: "coverage",
testMatch: ["**/__tests__/**/*.ts"],
};
// Type test functions
const testFn: Global.TestFn = async () => {
// Test implementation
};
// Type hooks
const hookFn: Global.HookFn = async () => {
// Setup or teardown logic
};Jest Types is organized into five main namespace modules:
Each module provides complete type coverage for its respective domain, enabling type-safe Jest usage and plugin development.
Core types for Jest's global test functions, hooks, and test organization. Essential for typing test files and custom test utilities.
interface TestFrameworkGlobals {
it: ItConcurrent;
test: ItConcurrent;
fit: ItBase & { concurrent?: ItConcurrentBase };
xit: ItBase;
xtest: ItBase;
describe: Describe;
xdescribe: DescribeBase;
fdescribe: DescribeBase;
beforeAll: HookBase;
beforeEach: HookBase;
afterEach: HookBase;
afterAll: HookBase;
}
type TestFn = PromiseReturningTestFn | GeneratorReturningTestFn | DoneTakingTestFn;
type HookFn = TestFn;
type DoneFn = (reason?: string | Error) => void;Complete configuration types for Jest setup including fake timers, coverage, module resolution, and test execution options.
interface InitialOptions {
// Core configuration
testEnvironment?: string;
testMatch?: Array<string>;
testRegex?: string | Array<string>;
collectCoverage?: boolean;
coverageDirectory?: string;
// Fake timers configuration
fakeTimers?: FakeTimers;
// Module configuration
moduleNameMapper?: Record<string, string | Array<string>>;
moduleFileExtensions?: Array<string>;
// Transform configuration
transform?: Record<string, string | [string, Record<string, unknown>]>;
}
interface GlobalConfig {
bail: number;
collectCoverage: boolean;
coverageDirectory: string;
maxWorkers: number;
testPathPatterns: TestPathPatterns;
// ... extensive configuration options
}Types for Jest's Circus test runner including event handling, test execution state, and test organization structures.
interface State {
currentDescribeBlock: DescribeBlock;
currentlyRunningTest?: TestEntry | null;
hasFocusedTests: boolean;
rootDescribeBlock: DescribeBlock;
testTimeout: number;
unhandledErrors: Array<Exception>;
}
interface TestEntry {
type: 'test';
fn: TestFn;
name: TestName;
parent: DescribeBlock;
mode: TestMode;
concurrent: boolean;
timeout?: number;
status?: TestStatus | null;
}
type Event = SyncEvent | AsyncEvent;Types for test execution results, assertions, and error handling to support test reporting and analysis.
interface AssertionResult {
ancestorTitles: Array<string>;
duration?: number | null;
failing?: boolean;
failureDetails: Array<unknown>;
failureMessages: Array<string>;
fullName: string;
numPassingAsserts: number;
status: Status;
title: string;
}
interface SerializableError {
code?: unknown;
message: string;
stack: string | null | undefined;
type?: string;
}Types for Jest's code transformation system enabling custom transformers and build tool integration.
interface TransformResult {
code: string;
originalCode: string;
sourceMapPath: string | null;
}