Skip to content
Back to skills

Jest Knowledge Patch

ASecurity

Jest

  • 25 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 5, 2026
developmenttypescriptgoreactnodeapi

Works with

  • terminal
  • cli
  • api

Security analysis

A100/100

Pro scans all 9 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill jest-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Jest Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Jest Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-jest-knowledge-patch/badge)](https://www.skillsdirectory.com/skills/nevaberry-jest-knowledge-patch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: jest-knowledge-patch
description: Jest
version: "30.5.2"
license: MIT
metadata:
  author: Nevaberry
---


# Jest compatibility guidance

Load this skill when upgrading Jest or working on configuration, test discovery,
module loading, mocks, snapshots, timers, environments, reporters, or integrations.
Use the topic references for detailed behavior and version-specific guidance.

## Reference index

| Reference | Topics |
| --- | --- |
| [Migration and compatibility](references/migration-and-compatibility.md) | Node support, dependency requirements, package exports, removed APIs, jsdom, glob matching |
| [Configuration and projects](references/configuration-and-projects.md) | Config files and types, project settings, worker lifecycle, custom runners |
| [CLI and discovery](references/cli-and-discovery.md) | Flag values, path patterns, filters, discovery, collection, failed files, version reporting |
| [Modules and transforms](references/modules-and-transforms.md) | Native ESM, CommonJS interoperability, resolution, module identity, ESM mocks, sandbox APIs, TypeScript |
| [Matchers, mocks, and snapshots](references/matchers-mocks-and-snapshots.md) | Assertion behavior, matcher and mock types, argument-based mocks, test titles, snapshot serialization |
| [Timers, retries, and lifecycle](references/timers-retries-and-lifecycle.md) | Promise rejections, async setup, global cleanup, leak detection, fake timers, Temporal, group retries |
| [Reporting and integrations](references/reporting-and-integrations.md) | Reporter results, structured errors, coverage, CLI parsing, sequencers, runtime construction, source maps |

## Breaking changes and deprecations

### Runtime and package requirements

Jest 30 drops Node.js 19 and 21 support. Update CI jobs and local environments
that still use either release before upgrading.
Both `babel-jest` and `babel-preset-jest` require `@babel/core` in the `^7.11` range.

Jest packages expose ESM entry points through `exports`. Migrate private imports
such as `jest-runner/build/testWorker` to documented package exports: bundling
removed internal file paths. The `jest-repl` package was removed and deprecated
in 30.0.1.

### Removed mock types and deprecated callsite lookup

`MockFunctionMetadata`, `MockFunctionMetadataType`, and `SpyInstance` were removed
from the public API. Use `jest.Spied<typeof target.method>` to annotate a spy on
`target.method`.

The standalone `getCallsite` export from `@jest/source-map` is deprecated.
Use `getCallsite` on a `SourceMapSupport` instance.

### CLI and programmatic contracts

Value-taking flags require arguments, for example `--maxWorkers=50%` or
`--selectProjects unit`. The CLI flag is `--testPathPatterns`; repeat it for
multiple patterns. Relative CLI patterns match test paths relative to the project root.

```sh
npx jest --testPathPatterns=unit --testPathPatterns=integration
```

Programmatic watch callers that supplied `testPathPattern` now need to pass a
`TestPathPatterns` instance. Pass `globalConfig` when constructing a Jest `Runtime`;
the argument is required in Jest 30.

A module passed to `--filter` must return an object with a `filtered` array of test paths.

```js
module.exports = testPaths => ({
  filtered: testPaths.filter(path => path.endsWith('.unit.test.js')),
});
```

### Global settings in multi-project runs

In 30.5.1, Jest warns if an individual project config sets `reporters`,
`coverageReporters`, `workerIdleMemoryLimit`, `cwd`, `runnerOptions`, `maxWorkers`,
or `coverageThreshold`. Put these in the root config (`--config` when supplied
alongside `--projects`) or in the first `--projects` entry when there is no root config.

### Mock paths and custom environments

The path passed to `jest.mock()` must match the file's casing, including on
case-insensitive file systems. For `filename.js`, use `jest.mock('./filename.js')`.

The jsdom upgrade can break tests that mock `window.location`. Use
`@jest/environment-jsdom-abstract` to compose an environment with your own jsdom
implementation. That package declares `@types/jsdom` as a peer dependency;
include it when installing the package for a custom environment.

### Snapshot migration

Jest 30 replaces the `goo.gl` link in snapshot file headers. Run the following
across the suite to refresh existing files, even when serialized values are unchanged.

```sh
npx jest --updateSnapshot
```

Snapshots of an `Error` include its `cause` when present. The React serializer
omits empty-string children. `pretty-format` shows `ArrayBuffer` and `DataView`
in a human-readable format; review the new output when updating affected snapshots.

### CommonJS defaults imported from ESM

In 30.4.0, Jest unwraps Babel-style `__esModule` defaults and shares the CommonJS
module instance across ESM importers. In 30.4.1, the default import is always
`module.exports`. In 30.4.2, named imports also work for own properties on
function-valued `module.exports`.

## Configuration and test discovery

### Config files and project output

The `jest` field in `package.json` can point to a separate configuration file.
Jest recognizes `jest.config.cts` and `jest.config.mts`. If Node runs with native
TypeScript type stripping enabled, Jest can load a TypeScript config without a
separate TypeScript loader. Config loading supports `Node16`, `NodeNext`, and
`Bundler` for `moduleResolution` in the project's `tsconfig.json`.

Set `verbose` or `silent` in an entry under `projects` to override the corresponding
global setting for that project's tests. Project configs can contain `collectCoverage`
and `coverageProvider` without a validation warning.

### Discover files and individual tests

Default `testMatch` finds `.mjs`, `.cjs`, `.mts`, and `.cts` files with usual test
names, such as `smoke.test.mjs`. As of 30.0.5, `testMatch` accepts a single glob
string, for example `testMatch: '**/*.unit.test.js'`.

```sh
npx jest --listTests --json --outputFile=tests.json
npx jest --collect-tests
```

`--outputFile` with `--listTests` saves discovered test paths. `--collect-tests`
discovers and lists individual tests without running their bodies.
`--collectTests` expands `test.each` and `describe.each`; its status counts account
for `--testNamePattern` and focused tests such as `.only` or `fdescribe`.
The `wouldRun` flag identifies tests that would execute in a real run.
`jest --onlyFailures` includes files whose previous run failed during loading or compilation.

## Module loading and resolution

### Requiring native ES modules

On Node 24.9 and later, Jest supports CommonJS `require()` of ES modules that can
be evaluated synchronously, with no top-level `await` in the module or its dependencies.
Jest can load a `.js` file with ESM syntax as native ESM without a `"type": "module"`
declaration. On Node 24.9 and later, `require()` also tries the ESM loader if the
CommonJS parser rejects the file's ESM syntax.

On Node versions older than 24.9, requiring a file marked as ESM can fall back to a configured
transform that converts it to CommonJS. Remaining untransformed ESM syntax produces
`ERR_REQUIRE_ESM`. Untransformed ESM syntax in `.cjs`, or in `.js` within a
`"type": "commonjs"` package, produces a CommonJS parse error.

### ESM mocks and sandbox loader hooks

On Node 24.9 and later, static imports, dynamic `import()`, and `require()` honor
automocking and manual `__mocks__` for synchronously evaluable ES module graphs.
Automocking uses the real module namespace and requires a graph without top-level
`await`, an async-only resolver, or an async-only transformer.

`jest.unstable_mockModule()` applies when `require()` loads the mocked ES module
directly. On Node 24.9 and later, it also applies to static imports of mocked `data:` URLs.
ES module mock instances first loaded inside `jest.isolateModules()` or
`jest.isolateModulesAsync()` stay scoped to the callback.

Calls to `module.register()` and `module.registerHooks()` inside tests throw because
those hooks would attach to the loader running Jest itself.

### Resolution and TypeScript source files

In 30.5.1, `moduleNameMapper` matches built-in specifiers as written again, reversing
30.5.0 normalization. Use `^(?:node:)?fs$` to match both `fs` and `node:fs`.
The default resolver honors `--preserve-symlinks` and `NODE_PRESERVE_SYMLINKS`.

On `main`, Jest uses Node's type stripping for `.ts`, `.mts`, and `.cts` source files
that have no matching Jest transformer.

## Matchers, mocks, and serialization

`mockFn.whenCalledWith(...args)` configures return values for matching calls.
Arguments accept asymmetric matchers, as in `mockFn.whenCalledWith(expect.any(String))`.

When `toThrow` takes a custom error instance, a thrown error with the same message
must also be an instance of that error class. `toStrictEqual` can compare
`structuredClone()` results across realms without failing solely because their
constructors came from different realms.

In printf-style `test.each` titles, `%$` inserts the one-based test-case number.
Jest serializes BigInt values such as `4n` as strings like `"4n"` in JSON test results
and `%j` titles, including BigInts nested in objects.

Use the matcher utilities' `SERIALIZABLE_PROPERTIES` hook to specify which custom
object properties appear in snapshots and assertion errors. Inline snapshot
formatting supports Prettier 3, and `pretty-format` supports React 19 values.

## Timers, retries, and environment lifecycle

`waitForUnhandledRejections` gives Jest an extra event-loop turn to observe a late
rejection handler before failing the test. Set it to `false` to skip the wait.
Files in `setupFilesAfterEnv` can export an async function in CommonJS or use
top-level `await` in ESM.

Set `testEnvironmentOptions.globalsCleanup` to `'on'` to clean up globals, keep the
default `'soft'` for warnings, or use `'off'` to disable the feature. Use
`protectProperties(globalThis.myCache)` from `jest-util` to protect a specific global object.

Use `jest.setTimerTickMode` to control how fake timers advance.
`jest.advanceTimersByTime()` and `jest.advanceTimersByTimeAsync()` accept a
`Temporal.Duration`. `jest.setSystemTime()` and the `now` option in
`jest.useFakeTimers()` accept a `Temporal.Instant` or `Temporal.ZonedDateTime`;
fake timers can control `Temporal.Now` methods.

Set `jest.retryTimes(2, {entireDescribe: true})` inside a `describe` block to retry
the group when one of its tests fails.

## Reporters and coverage

Reporter integrations can use `AssertionResult.retryMessages`,
`Circus.RunResult.unhandledErrorsDetailed`, and `formatErrorStack` from
`jest-message-util` to render nested causes and aggregate errors. Inner errors of
an `AggregateError` also appear in `failureMessages`, `retryReasons`, and `unhandledErrors`.
With `verbose` enabled, custom reporters can read buffered console output from `TestResult.console`.

Jest prints terminal coverage while writing JSON results with `--outputFile`.
The `global` coverage threshold applies to files outside configured path and glob
thresholds; each path or glob threshold applies to its matching files.

Files in this skill

  • SKILL.md8.5 KB
  • coverage.json622 B
  • references/cli-and-discovery.md2.2 KB
  • references/configuration-and-projects.md2 KB
  • references/matchers-mocks-and-snapshots.md2.7 KB
  • references/migration-and-compatibility.md2.9 KB
  • references/modules-and-transforms.md2.6 KB
  • references/reporting-and-integrations.md2.1 KB
  • references/timers-retries-and-lifecycle.md2.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.