{"record":{"id":"45453b6ad49b75f9","repo":"oxc-project/oxc","slug":"title-must-be-a-string","errorCode":null,"errorMessage":"Title must be a string","messagePattern":"Title must be a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/valid_title.rs","lineNumber":24,"sourceCode":"\nuse oxc_ast::{\n    AstKind,\n    ast::{Argument, BinaryExpression, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::CompactStr;\n\nuse crate::{\n    context::LintContext,\n    utils::{\n        JestFnKind, JestGeneralFnKind, PossibleJestNode, is_string_raw_member_expression,\n        parse_general_jest_fn_call,\n    },\n};\n\nfn title_must_be_string_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Title must be a string\")\n        .with_help(\"Replace your title with a string\")\n        .with_label(span)\n}\n\nfn empty_title_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Should not have an empty title\")\n        .with_help(\"Write a meaningful title for your test\")\n        .with_label(span)\n}\n\nfn duplicate_prefix_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Should not have duplicate prefix\")\n        .with_help(\"The function name already has the prefix, try to remove the duplicate prefix\")\n        .with_label(span)\n}\n\nfn accidental_space_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Should not have leading or trailing spaces\")","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/valid_title.rs#L6-L42","documentation":"Diagnostic from the shared jest/vitest `valid-title` rule (title_must_be_string_diagnostic). It fires when the title argument of a `describe`/`test`/`it`/`it.skip`-style block is not a string — a number, identifier, or interpolated template. Non-string titles break reporters and test filtering that assume text titles.","triggerScenarios":"`parse_general_jest_fn_call` resolves the jest call; when the title argument is not a string literal / raw template (is_string_raw_member_expression handles a few raw cases), the diagnostic fires. Examples: `test(123, fn)`, `it(someVariable, fn)`, `describe(`unit-${i}`, fn)` with interpolation.","commonSituations":"Data-driven tests that accidentally pass the row object/number as title instead of a template string; renaming constants and passing the identifier; migrated suites that stored titles in variables.","solutions":["Use a string literal: `it('adds numbers', fn)`.","For dynamic titles use a non-interpolated raw template or build a plain string: `it(`case ${name}`, fn)` is flagged when interpolated — prefer a literal or configure accordingly; simplest is a static string or `` it(name, fn) `` only when `name` is a string variable intended as the title and the rule option allows it (default requires literals).","If variable titles are intentional, review valid-title options or disable the rule for those lines."],"exampleFix":"// before\ntest(42, () => { /* ... */ });\n\n// after\ntest('returns 42', () => { /* ... */ });","handlingStrategy":"type-guard","validationCode":"function assertTitle(title: unknown, fnName: string): string {\n  if (typeof title !== 'string' || title.length === 0) {\n    throw new TypeError(`${fnName} requires a non-empty string title`);\n  }\n  return title;\n}","typeGuard":"function isStringTitle(t: unknown): t is string {\n  return typeof t === 'string';\n}\n// usage: test(isStringTitle(t) ? t : fallbackName, fn)","tryCatchPattern":null,"preventionTips":["Always type test titles as literals; if dynamic, build a string first and assert `typeof title === 'string'` in helpers.","Enable valid-title in CI so non-string titles fail fast.","Avoid interpolating counters into template titles unless your convention allows it."],"tags":["jest","vitest","oxlint","testing","test-title","valid-title"],"backgroundTag":"invalid-test-title","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}