close

jest/no-deprecated-functions

Configuration

PresetConfigured Value
✅ jestPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, jestPlugin } from '@rslint/core';

export default defineConfig([
  jestPlugin.configs.recommended,
  {
    rules: {
      'jest/no-deprecated-functions': 'error',
    },
  },
]);

Rule Details

Jest sometimes deprecates globals and jest helpers in favor of newer APIs. This rule flags calls to those deprecated members and reports a replacement. A fix rewrites the callee to the suggested API; bracket-style access is preserved (for example jest['genMockFromModule'] becomes jest['createMockFromModule']).

Which names are considered deprecated depends on the Jest version rslint uses for the file (from settings.jest.version or the resolved package.json dependency). A symbol is only reported once your configured major version is at least the version that deprecated it:

DeprecatedReplacementStarting at Jest major
jest.resetModuleRegistryjest.resetModules15
jest.addMatchersexpect.extend17
require.requireMockjest.requireMock21
require.requireActualjest.requireActual21
jest.runTimersToTimejest.advanceTimersByTime22
jest.genMockFromModulejest.createMockFromModule26

If the resolved Jest version is too old for any of these deprecations, the rule does not report them.

Examples of incorrect code for this rule (assuming a Jest version where the corresponding API is deprecated):

jest.resetModuleRegistry();
jest.addMatchers({});
require.requireMock('a');
require.requireActual('a');
jest.runTimersToTime(1000);
jest.genMockFromModule('m');

Examples of correct code for this rule:

jest.resetModules();
expect.extend({});
jest.requireMock('a');
jest.requireActual('a');
jest.advanceTimersByTime(1000);
jest.createMockFromModule('m');

Original Documentation