Skip to content
Back to skills

Jest Knowledge Patch

ASecurity

Jest

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

Works with

  • terminal
  • cli
  • api

Security analysis

A100/100

Pro scans all 7 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-nevaberry-plugins/badge)](https://www.skillsdirectory.com/skills/nevaberry-jest-knowledge-patch-nevaberry-plugins)

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 selection,
assertions, mocks, snapshots, execution, timers, module loading, transforms,
custom environments, or tooling integrations.

## Reference index

| Reference | Topics |
| --- | --- |
| [Migration and runtime](references/migration-and-runtime.md) | Node support, public package imports, runtime and sequencer integration, sandbox APIs, source maps, leak detection |
| [Configuration and CLI](references/configuration-and-cli.md) | Config files and types, project settings, path filters, discovery, collection, coverage, CLI integration |
| [Execution and timers](references/execution-and-timers.md) | Async setup, rejection handling, retries, fake timers, workers, table-driven titles, reporters, custom runners |
| [Assertions, mocks, and snapshots](references/assertions-mocks-and-snapshots.md) | Mock types and calls, matchers, assertion behavior, snapshot refresh, serializers and tooling |
| [Modules, transforms, and environments](references/modules-transforms-and-environments.md) | Babel, TypeScript stripping, native ESM, CommonJS interoperability, resolution, ESM mocks, jsdom, global cleanup |

## 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.

Jest packages expose ESM entry points through `exports`. Migrate private imports
such as `jest-runner/build/testWorker` to documented package exports, since
bundling removed internal file paths.

Both `babel-jest` and `babel-preset-jest` require `@babel/core` in the `^7.11`
range. The `jest-repl` package was removed and deprecated in 30.0.1.

### CLI and programmatic integration

Jest rejects value-taking flags with missing arguments. Use values such as
`--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. A module passed to `--filter` must return an object
with a `filtered` array of test paths.

Pass the required `globalConfig` argument when constructing a Jest `Runtime`.
Custom subclasses of `TestSequencer` receive `globalConfig` and `contexts`.

### Mock types and paths

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

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')`.

### Multi-project global settings

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. The configuration reference preserves the earlier project-option behavior.

### Loader hooks and source maps

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

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

## Configuration and test discovery

The `jest` field in `package.json` can point to a separate configuration file.
Jest recognizes `jest.config.cts` and `jest.config.mts`.

With Node's native TypeScript type stripping enabled, Jest can load a TypeScript
config without a separate TypeScript loader. Config loading works with
`Node16`, `NodeNext`, or `Bundler` as `tsconfig.json`'s `moduleResolution`.

Import `GlobalConfig` and `ProjectConfig` from the public `jest` package.
Set `verbose` or `silent` in an entry under `projects` to override that project's
corresponding global setting. Project configs can contain `collectCoverage` and
`coverageProvider` without a validation warning.

Default `testMatch` finds `.mjs`, `.cjs`, `.mts`, and `.cts` test files with the
usual test naming conventions, such as `smoke.test.mjs`. As of 30.0.5,
`testMatch` also accepts a single glob string.

Use `--outputFile` with `--listTests` to save discovered test paths:

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

Use `--collect-tests` to discover and list 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. CLI integrations can import `buildArgv` from `jest-cli`.

## Setup, cleanup, and environments

Files in `setupFilesAfterEnv` can export an async function in CommonJS or use
top-level `await` in ESM.

`waitForUnhandledRejections` gives Jest an extra turn of the event loop to observe
a late rejection handler before failing the test. Set it to `false` to skip the wait.

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.

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

## Native ESM and transforms

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. The modules reference retains the earlier feature-check behavior.

Jest can load a `.js` file with ESM syntax as native ESM even 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.

Untransformed ESM syntax in a `.cjs` file or a `.js` file in a
`"type": "commonjs"` package produces a CommonJS parse error.

For ESM importing CommonJS, 30.4.0 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`.

Native ESM exposes `import.meta.resolve(specifier)`, `import.meta.filename`, and
`import.meta.dirname`. Distinct URL query strings or fragments produce separate
ES module instances, and the suffix is visible in `import.meta.url`.

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.

Virtual module registrations made with `jest.unstable_mockModule()` take effect
for ESM imports. Explicit factories also apply when `require()` loads the mocked
ES module directly and, on Node 24.9 and later, to static imports of mocked `data:`
URLs. ES module mock instances first loaded inside `jest.isolateModules()` or
`jest.isolateModulesAsync()` stay scoped to the callback.

On `main`, Jest uses Node's type stripping for `.ts`, `.mts`, and `.cts` source
files with no matching Jest transformer. `babel-jest` can collect coverage from
`.mts` and `.cts` files.

## Assertions, mocks, and test titles

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.

`mockFn.whenCalledWith(...args)` configures return values for matching arguments
and accepts asymmetric matchers, such as
`mockFn.whenCalledWith(expect.any(String))`.

In printf-style `test.each` titles, `%$` inserts the one-based test-case number.
On `main`, `$variable` interpolation treats regex metacharacters in column names
literally. BigInt values such as `4n` serialize as strings like `"4n"` in JSON
test results and `%j` titles, including when nested in an object.

## Timers, retries, and workers

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.

Set `workerIdleMemoryLimit: 0` to restart worker child processes after every
completed task. `workerGracefulExitTimeout` controls how long workers have to exit
before Jest force-kills them.

## Snapshots, results, and coverage

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

Error snapshots include `cause` when present. The React serializer omits
empty-string children, and `pretty-format` shows `ArrayBuffer` and `DataView`
values in a human-readable format. Review the new output when updating affected
snapshots. `pretty-format` also supports React 19 values.

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. A failing snapshot assertion can satisfy
`test.failing` under `jest-circus`.

Reporter integrations can use `AssertionResult.retryMessages`,
`Circus.RunResult.unhandledErrorsDetailed`, and `formatErrorStack` from
`jest-message-util` to render nested causes and aggregate errors. Custom reporters
can read buffered console output from `TestResult.console` with `verbose` enabled.

Jest prints terminal coverage while writing JSON test results to `--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.json621 B
  • references/assertions-mocks-and-snapshots.md4.7 KB
  • references/configuration-and-cli.md4.9 KB
  • references/execution-and-timers.md4.4 KB
  • references/migration-and-runtime.md4.5 KB
  • references/modules-transforms-and-environments.md4.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.