oxc-project/oxc · warning

Do not call `jest.setTimeout` multiple times

Error message

Do not call `jest.setTimeout` multiple times

What it means

This is the 'called multiple times' branch of oxlint's 'jest/no-confusing-set-timeout' rule. It reports a jest.setTimeout call when an earlier jest.setTimeout call already appeared in the file. Because only the last call takes effect, earlier calls are dead configuration that silently misleads readers about the active timeout.

Source

Thrown at crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs:20

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::{AstNode, NodeId, ReferenceId};
use oxc_span::Span;
use rustc_hash::{FxHashMap, FxHashSet};

use crate::{
    context::LintContext,
    rule::Rule,
    utils::{PossibleJestNode, collect_possible_jest_call_node, parse_jest_fn_call},
};

fn non_global_set_timeout_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("`jest.setTimeout` should only be called in a global scope")
        .with_label(span)
}

fn no_multiple_set_timeouts_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Do not call `jest.setTimeout` multiple times")
        .with_help("Only the last call to `jest.setTimeout` will have an effect.")
        .with_label(span)
}

fn no_unorder_set_timeout_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("`jest.setTimeout` should be placed before any other jest methods.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoConfusingSetTimeout;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow confusing usages of `jest.setTimeout`.
    ///
    /// ### Why is this bad?

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Delete all but one jest.setTimeout call, keeping the single intended value at module scope.
  2. Prefer config: set testTimeout in jest.config.js (or jest.config.ts) and remove all per-file setTimeout calls.
  3. If different files need different timeouts, keep exactly one top-level call per file with the right value.
  4. Suppress intentional duplicates with an inline oxlint-disable-next-line comment.

Example fix

// before
jest.setTimeout(5000);
jest.setTimeout(30000);

// after
jest.setTimeout(30000);

// or in jest.config.js
module.exports = { testTimeout: 30000 };
Defensive patterns

Strategy: validation

Validate before calling

// count jest.setTimeout occurrences per file; >1 will be flagged
const { execSync } = require('node:child_process');
console.log(execSync("rg -c 'jest\\.setTimeout' tests/ | awk -F: '$2 > 1'", { encoding: 'utf8' }));

Prevention

When it happens

Trigger: Enable the rule and lint a file containing two or more jest.setTimeout(...) calls at any scope; every call except the first (as tracked via a NodeId set during traversal) gets this diagnostic, with help text 'Only the last call ... will have an effect.'

Common situations: Copy-pasted test files merge setup blocks, or a shared setup file and a local file both set timeouts. During migration to testTimeout in jest.config.js teams often leave the old setTimeout calls behind, producing duplicates.

Understand the failure class

Related errors


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