{"record":{"id":"1d9436a0abf24626","repo":"oxc-project/oxc","slug":"use-tobeundefined-instead","errorCode":null,"errorMessage":"Use `toBeUndefined` instead.","messagePattern":"Use `toBeUndefined` instead\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs","lineNumber":23,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    utils::{\n        KnownMemberExpressionProperty, ParsedExpectFnCall, PossibleJestNode, is_equality_matcher,\n        parse_expect_jest_fn_call,\n    },\n};\n\nfn use_to_be(source_text: &str, suggestion: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `toBe` when expecting primitive literals.\")\n        .with_help(format!(\"Replace `{source_text}` with `{suggestion}`.\"))\n        .with_label(span)\n}\n\nfn use_to_be_undefined(source_text: &str, suggestion: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `toBeUndefined` instead.\")\n        .with_help(format!(\"Replace `{source_text}` with `{suggestion}`.\"))\n        .with_label(span)\n}\n\nfn use_to_be_defined(source_text: &str, suggestion: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `toBeDefined` instead.\")\n        .with_help(format!(\"Replace `{source_text}` with `{suggestion}`.\"))\n        .with_label(span)\n}\n\nfn use_to_be_null(source_text: &str, suggestion: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `toBeNull` instead.\")\n        .with_help(format!(\"Replace `{source_text}` with `{suggestion}`.\"))\n        .with_label(span)\n}\n\nfn use_to_be_na_n(source_text: &str, suggestion: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `toBeNaN` instead.\")","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs#L5-L41","documentation":"Warning from the oxlint `jest/prefer-to-be` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs:23). The implementation detects `expect(...)` chained with an equality matcher whose argument is the `undefined` literal, and suggests the dedicated `toBeUndefined()` matcher, which yields clearer failure output.","triggerScenarios":"`expect(value).toEqual(undefined)` or `expect(value).toBe(undefined)` (any equality matcher with `undefined` as the argument). Also fires through the negation path: `expect(value).not.toBeUndefined()` maps to `toBeDefined`, per the `has_not_modifier` branch in the source.","commonSituations":"Asserting that a lookup returned nothing, e.g. `expect(map.get(key)).toEqual(undefined)`; refactors after enabling the jest recommended preset in oxlint; code ported from other frameworks that use `assert(value === undefined)`.","solutions":["Replace with `expect(value).toBeUndefined()`.","For negated forms use the mirror matcher: `expect(value).toBeDefined()` instead of `expect(value).not.toBeUndefined()` (the rule flags both directions).","Suppress inline with `// oxlint-disable-next-line jest/prefer-to-be` if needed."],"exampleFix":"// before\nexpect(cache.get('missing')).toEqual(undefined);\n\n// after\nexpect(cache.get('missing')).toBeUndefined();","handlingStrategy":"validation","validationCode":"// rg -n \"\\.toEqual\\(undefined\\)\" tests/ -t ts -t js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ban `toEqual(undefined)` by keeping prefer-to-be enabled in CI lint","Use toBeUndefined/toBeDefined in code review checklists","Run oxlint in editor (LSP) so the suggestion appears as you type"],"tags":["jest","vitest","oxlint","matcher","undefined"],"backgroundTag":"jest-prefer-to-be","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}