{"record":{"id":"32a3d8aa519bbd30","repo":"oxc-project/oxc","slug":"use-tobenull-instead","errorCode":null,"errorMessage":"Use `toBeNull` instead.","messagePattern":"Use `toBeNull` instead\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs","lineNumber":35,"sourceCode":"    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\nRecommends using `toBe` matcher for primitive literals and specific\nmatchers for `null`, `undefined`, and `NaN`.\n\n### Why is this bad?\n\nWhen asserting against primitive literals such as numbers and strings,","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs#L17-L53","documentation":"Warning from the oxlint `jest/prefer-to-be` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs:35). When an equality matcher receives the `null` literal (detected by the `first_matcher_arg.is_null()` style check in the run implementation), the rule recommends the dedicated `toBeNull()` matcher.","triggerScenarios":"`expect(value).toEqual(null)`, `expect(value).toBe(null)`, or `expect(value).toStrictEqual(null)` - any equality matcher whose single argument is the literal `null`.","commonSituations":"Asserting absent optional values such as `expect(queryResult.row).toEqual(null)`; migrating codebases where `toEqual(null)` was the house style; enabling jest recommended rules in oxlint CI.","solutions":["Change to `expect(value).toBeNull()`.","For negations use `expect(value).not.toBeNull()` (still allowed) or restructure to a more specific matcher if one fits.","Suppress inline with `// oxlint-disable-next-line jest/prefer-to-be` for deliberate cases."],"exampleFix":"// before\nexpect(queryResult.row).toEqual(null);\n\n// after\nexpect(queryResult.row).toBeNull();","handlingStrategy":"validation","validationCode":"// rg -n \"\\.toEqual\\(null\\)\" tests/ -t ts -t js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use toBeNull/toBeUndefined/toBeNaN for the three singleton values","Enable the rule in CI so regressions fail the lint step"],"tags":["jest","vitest","oxlint","matcher","null"],"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"}