Comprehensive TypeScript type definitions for the Jest testing framework ecosystem providing shared types for configuration, test results, transforms, and global utilities.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Types for test execution results, assertions, and error handling to support test reporting and analysis. These types avoid large dependency trees while providing complete test result structures.
Core status values for test execution outcomes.
/**
* Test execution status values
*/
type Status =
| 'passed' // Test completed successfully
| 'failed' // Test failed with errors
| 'skipped' // Test was skipped (test.skip)
| 'pending' // Test is pending execution
| 'todo' // Test is marked as todo (test.todo)
| 'disabled' // Test is disabled
| 'focused'; // Test is focused (test.only)Types for representing test location information.
/**
* Source code location (line and column)
*/
type Callsite = {
column: number;
line: number;
};Complete interface for individual test assertion results.
/**
* Result of an individual test assertion
* Designed to avoid huge dependency trees for result processing
*/
interface AssertionResult {
/** Array of ancestor describe block titles */
ancestorTitles: Array<string>;
/** Test execution duration in milliseconds */
duration?: number | null;
/** Test start timestamp */
startAt?: number | null;
/**
* Whether test.failing() was used
* @see https://jestjs.io/docs/api#testfailingname-fn-timeout
*/
failing?: boolean;
/**
* Raw failure details (may lose function/symbol types)
* Function or symbol types may be lost because they cannot be
* serialized correctly between workers, but information about
* them will be available in failureMessages
*/
failureDetails: Array<unknown>;
/** Array of failure message strings */
failureMessages: Array<string>;
/** Full test name including ancestor titles */
fullName: string;
/** Number of times test was invoked (for retries) */
invocations?: number;
/** Source location of the test */
location?: Callsite | null;
/** Number of assertions that passed */
numPassingAsserts: number;
/** Reasons for test retries */
retryReasons?: Array<string>;
/** Test execution status */
status: Status;
/** Test title (without ancestor context) */
title: string;
}Interface for errors that can be serialized between Jest workers.
/**
* Error that can be serialized between workers
* Used to avoid dependency trees while maintaining error information
*/
interface SerializableError {
/** Error code (if available) */
code?: unknown;
/** Error message */
message: string;
/** Error stack trace */
stack: string | null | undefined;
/** Error type/name */
type?: string;
}Usage Examples:
import type { TestResult } from "@jest/types";
// Process test assertion results
const processAssertionResult = (result: TestResult.AssertionResult) => {
const fullPath = [...result.ancestorTitles, result.title].join(' > ');
if (result.status === 'passed') {
console.log(`✓ ${fullPath} (${result.duration}ms)`);
} else if (result.status === 'failed') {
console.log(`✗ ${fullPath}`);
result.failureMessages.forEach(message => {
console.log(` ${message}`);
});
}
};
// Create a serializable error
const createSerializableError = (error: Error): TestResult.SerializableError => {
return {
message: error.message,
stack: error.stack,
type: error.name,
code: (error as any).code,
};
};
// Check test status
const isTestPassing = (result: TestResult.AssertionResult): boolean => {
return result.status === 'passed';
};
// Get test summary
const getTestSummary = (results: TestResult.AssertionResult[]) => {
const passed = results.filter(r => r.status === 'passed').length;
const failed = results.filter(r => r.status === 'failed').length;
const skipped = results.filter(r => r.status === 'skipped').length;
const todo = results.filter(r => r.status === 'todo').length;
return { passed, failed, skipped, todo, total: results.length };
};