oxc-project/oxc · warning

{deprecated:?} has been deprecated in favor of {new:?}

Error message

{deprecated:?} has been deprecated in favor of {new:?}

What it means

This is oxlint's 'jest/no-deprecated-functions' diagnostic. It maps statically-known member accesses onto a deprecation table (jest.resetModuleRegistry→jest.resetModules since Jest 15, jest.addMatchers→expect.extend since 17, require.requireMock/requireActual→jest.* since 21, jest.runTimersToTime→jest.advanceTimersByTime since 22, jest.genMockFromModule→jest.createMockFromModule since 26) and reports usages when your configured Jest version is at or above the deprecation version. The rule carries an autofix that rewrites the member expression to its replacement. Version comes from settings.jest.version or the rule's jest.version option, defaulting to 29.

Source

Thrown at crates/oxc_linter/src/rules/jest/no_deprecated_functions.rs:11

use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;

use crate::{context::LintContext, rule::Rule};

fn deprecated_function(deprecated: &str, new: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("{deprecated:?} has been deprecated in favor of {new:?}"))
        .with_label(span)
}

#[derive(Debug, Clone, Deserialize, JsonSchema)]
#[serde(default, deny_unknown_fields)]
pub struct JestConfig {
    /// The version of Jest being used.
    version: usize,
}

impl Default for JestConfig {
    fn default() -> Self {
        Self { version: 29 }
    }
}

#[derive(Debug, Deserialize, JsonSchema)]
#[serde(default, deny_unknown_fields)]

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Apply the provided autofix (oxlint --fix) or manually replace the deprecated call, e.g. jest.genMockFromModule(m) → jest.createMockFromModule(m).
  2. Set your real Jest major in .oxlintrc.json under settings.jest.version (e.g. "settings": { "jest": { "version": "27" } }) so only genuinely deprecated APIs for your version are flagged.
  3. If you must keep a deprecated call temporarily, suppress it with // oxlint-disable-next-line jest/no-deprecated-functions.
  4. After Jest upgrades, re-run the rule to catch newly deprecated functions.

Example fix

// before
const mock = jest.genMockFromModule('./db');
const actual = require.requireActual('./db');

// after
const mock = jest.createMockFromModule('./db');
const actual = jest.requireActual('./db');
Defensive patterns

Strategy: validation

Validate before calling

// detect deprecated Jest APIs before linting
const { execSync } = require('node:child_process');
console.log(execSync("rg -n 'jest\\.(resetModuleRegistry|addMatchers|runTimersToTime|genMockFromModule)|require\\.(requireMock|requireActual)' tests/", { encoding: 'utf8' }));

Prevention

When it happens

Trigger: Enable the rule (default Jest version 29) and lint code containing a static or computed member expression on the identifiers jest or require whose property matches the deprecation map, e.g. jest.genMockFromModule('./x'). Because 29 >= 26, the diagnostic fires and the fixer replaces the span with the new name.

Common situations: Codebases upgraded across Jest majors keep old API calls that still work but are slated for removal (genMockFromModule is removed in Jest 30). A wrong jest version setting — e.g. settings.jest.version left at an old value — either hides real deprecations or, when defaulted to 29, flags calls that were fine on the project's actual old Jest.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/e255758a1eb1604a. Report an issue: GitHub.