oxc-project/oxc · error

Second argument must be a function

Error message

Second argument must be a function

What it means

Diagnostic from the oxlint `jest/valid-describe-callback` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/valid_describe_callback.rs:18). This variant ('Second argument must be a function') fires when the describe callback slot is occupied by something that is not a function - an options object, string, or array. The shared builder `valid_describe_callback_diagnostic(x1, x2, span3)` emits the message with a help string.

Source

Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/valid_describe_callback.rs:18

use oxc_ast::{
    AstKind,
    ast::{Argument, Expression, FunctionBody, Statement},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{GetSpan, Span};

use crate::{
    context::LintContext,
    utils::{JestFnKind, JestGeneralFnKind, PossibleJestNode, parse_general_jest_fn_call},
};

fn valid_describe_callback_diagnostic(
    x1: &'static str,
    x2: &'static str,
    span3: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(x1).with_help(x2).with_label(span3)
}

#[derive(Clone, Copy)]
pub struct ValidDescribeCallbackOptions {
    allow_async_describe_callback: bool,
    allow_describe_options_argument: bool,
}

impl ValidDescribeCallbackOptions {
    pub const JEST: Self =
        Self { allow_async_describe_callback: false, allow_describe_options_argument: false };

    pub const VITEST: Self =
        Self { allow_async_describe_callback: true, allow_describe_options_argument: true };
}

pub fn run<'a>(
    possible_jest_node: &PossibleJestNode<'a, '_>,

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Make the second argument a function: `describe('title', () => { /* tests */ })`.
  2. If you intended per-call options, describe does not support them (except via the allow-describe-options-argument escape hatch); put timeouts on the test or use `jest.setTimeout`.
  3. Check the callback identifier actually resolves - an undefined import produces this same error.

Example fix

// before
describe('sync', { timeout: 5000 });

// after
describe('sync', () => {
  test('finishes', () => { /* ... */ }, 5000);
});
Defensive patterns

Strategy: validation

Validate before calling

// rg -nU "describe\([^)]*,\s*(\{|['\"]|\[)" tests/ -t ts -t js

Type guard

// Guard before running a suite built from data (JS):
function isDescribeArgsOk(title, cb) {
  return typeof title === 'string' && typeof cb === 'function';
}

Prevention

When it happens

Trigger: `describe('title', { timeout: 1000 })`, `describe('title', 'not a function')`, or passing a non-callable second argument. Note the `allow_describe_options_argument` option (Jest preset sets it false) exists in the source - when enabled, an options object as third argument is tolerated.

Common situations: Confusing describe with test, which does accept per-test options objects; migrating suites where someone tried to pass jest options to describe; callback variable that is undefined due to an import typo.

Related errors


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