Linter · Rules
jest/no-deprecated-functions
Disallow Jest functions that have been renamed or replaced
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
Reported:
import { jest } from "@jest/globals";
jest.useFakeTimers();
jest.runTimersToTime(1000);
const api = jest.genMockFromModule("./api");
Not reported:
import { jest } from "@jest/globals";
jest.useFakeTimers();
jest.advanceTimersByTime(1000);
const api = jest.createMockFromModule("./api");
The full list:
| Reported | From Jest | Write instead |
|---|---|---|
jest.resetModuleRegistry | 15 | jest.resetModules |
jest.addMatchers | 17 | expect.extend |
require.requireMock | 21 | jest.requireMock |
require.requireActual | 21 | jest.requireActual |
jest.runTimersToTime | 22 | jest.advanceTimersByTime |
jest.genMockFromModule | 26 | jest.createMockFromModule |
Options
| Option | Default | What 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:
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.