{"record":{"id":"6a9ff77f6f2356c0","repo":"oxc-project/oxc","slug":"use-tobedefined-instead","errorCode":null,"errorMessage":"Use `toBeDefined` instead.","messagePattern":"Use `toBeDefined` instead\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs","lineNumber":29,"sourceCode":"        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.\")\n        .with_help(format!(\"Replace `{source_text}` with `{suggestion}`.\"))\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs#L11-L47","documentation":"Warning from the oxlint `jest/prefer-to-be` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs:29). The source's `has_not_modifier` branch maps `expect(x).not.toBeUndefined()` (and `toEqual(undefined)` negations) to the dedicated `toBeDefined()` matcher for better failure messages.","triggerScenarios":"`expect(value).not.toBeUndefined()` or `expect(value).not.toEqual(undefined)` - an expect call with the `not` modifier paired with an undefined-related equality assertion.","commonSituations":"Guards asserting that a field was set: `expect(config.apiKey).not.toBeUndefined()`; optionality checks on function results; suites linted with the jest plugin's recommended rules.","solutions":["Rewrite as `expect(value).toBeDefined()`.","Keep the positive form for the inverse case: `expect(value).toBeUndefined()`.","Suppress with `// oxlint-disable-next-line jest/prefer-to-be` if the `not` phrasing is intentional."],"exampleFix":"// before\nexpect(config.apiKey).not.toBeUndefined();\n\n// after\nexpect(config.apiKey).toBeDefined();","handlingStrategy":"validation","validationCode":"// rg -n \"\\.not\\.toBeUndefined\\(\\)\" tests/ -t ts -t js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer the positive matcher form (toBeDefined) when writing new assertions","Keep prefer-to-be in the enforced rule set so negations are flagged automatically"],"tags":["jest","vitest","oxlint","matcher","defined"],"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"}