jest/no-deprecated-functions

Disallow Jest functions that have been renamed or replaced

fixable

Jest has renamed or moved some of its functions. The old names keep working for a while and then get removed, so a test that uses one breaks on a later upgrade.

--fix writes the new name.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"jest/no-deprecated-functions" = "error" # or "warn"

Examples#

example.ts2 problems
import { jest } from "@jest/globals";

jest.useFakeTimers();
jest.runTimersToTime(1000);

const api = jest.genMockFromModule("./api");
example.tsNo problems
import { jest } from "@jest/globals";

jest.useFakeTimers();
jest.advanceTimersByTime(1000);

const api = jest.createMockFromModule("./api");

The full list:

ReportedFrom JestWrite instead
jest.resetModuleRegistry15jest.resetModules
jest.addMatchers17expect.extend
require.requireMock21jest.requireMock
require.requireActual21jest.requireActual
jest.runTimersToTime22jest.advanceTimersByTime
jest.genMockFromModule26jest.createMockFromModule

Options#

OptionDefaultWhat it does
jest.version"29"Your Jest version, as a string. A function is only reported starting from the version in the table above.
bunfig.toml
[lint.rules]
"jest/no-deprecated-functions" = ["error", { jest = { version = "25.1.0" } }]

jest.genMockFromModule is still the current name in Jest 25:

example.tswith { "jest": { "version": "25.1.0" } }No problems
import { jest } from "@jest/globals";

const api = jest.genMockFromModule("./api");

If you set settings.jest.version ([lint.settings.jest] in bunfig.toml, or settings in an ESLint or oxlint config), that version is used instead of the option.