jest-testing-expert

Diagnose and resolve Jest configuration, mocking, async testing, and coverage issues.

3|Updated Jan 15, 2026
One-click install
npx skills add https://github.com/trudyan141/my-antigravity-agents-kit --skill jest-testing-expert-trudyan141
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: jest-testing-expert
Source: https://github.com/trudyan141/my-antigravity-agents-kit/tree/main/templates/.agent/skills/jest-expert
Command: npx skills add https://github.com/trudyan141/my-antigravity-agents-kit --skill jest-testing-expert-trudyan141

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Jest test suites often break due to configuration errors, module hoisting issues, ESM/CommonJS conflicts, timer mocking problems, and slow CI execution. This Skill provides expert-level diagnosis and fixes for over 50 common Jest problems, plus production-ready configuration patterns. ## Core Features & Use Cases - Configuration Mastery: Production-ready jest.config.js patterns covering module resolution, transforms, coverage thresholds, and TypeScript/ESM integration with ts-jest. - Advanced Mocking & Async Patterns: Solutions for jest.mock hoisting issues, timer control with fake timers, promise testing with resolves/rejects, and race condition handling. - Performance & CI Optimization: Worker parallelization tuning, memory leak detection, cache management, and flaky test debugging for CI pipelines. - Use Case: Your tests fail only in CI with 'Cannot use import statement outside a module' errors. This Skill diagnoses the ESM/CommonJS mismatch and provides the exact ts-jest ESM preset configuration to fix it. ## Quick Start Ask the assistant to diagnose why your Jest tests fail with module resolution or timeout errors and provide a corrected jest.config.js.

Frequently Asked Questions about jest-testing-expert

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix 'Cannot use import statement outside a module' in Jest?▼

This error comes from an ESM/CommonJS mismatch. Either add "type": "module" to package.json with the ts-jest ESM preset and extensionsToTreatAsEsm, or configure babel-jest as the transform for JavaScript and TypeScript files.

How do I mock modules correctly with jest.mock hoisting?▼

jest.mock calls are hoisted above imports, so define the mock factory at the top of the file before imports take effect. Return an object with __esModule: true and jest.fn() implementations matching the module's exports.

Does Jest support TypeScript and ESM together?▼

Yes, use the ts-jest/presets/default-esm preset with extensionsToTreatAsEsm set to ['.ts'] and useESM enabled in the transform options. Add a moduleNameMapper mapping relative .js imports to their extensionless paths.

Why do my Jest tests pass locally but fail in CI?▼

CI failures usually stem from environment differences, stale caches, or parallel execution race conditions. Run with CI=true, NODE_ENV=test, --ci and --no-cache flags, and use --runInBand to isolate flaky parallel tests.

How do I fix Jest worker crashes and out-of-memory errors?▼

Reduce maxWorkers to match available CPU cores and increase Node.js memory with NODE_OPTIONS="--max-old-space-size=4096". Add afterEach cleanup with jest.clearAllMocks() and run with --detectLeaks to find memory leaks.

When should I avoid snapshot testing in Jest?▼

Avoid full-component snapshots that produce large, fragile files. Prefer targeted snapshots of specific elements or property matchers like expect.any(String) for dynamic values such as IDs and dates.