{"record":{"id":"2ab9079b66e6ca95","repo":"oxc-project/oxc","slug":"use-tobenan-instead","errorCode":null,"errorMessage":"Use `toBeNaN` instead.","messagePattern":"Use `toBeNaN` instead\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs","lineNumber":41,"sourceCode":"    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,\nthe equality matchers all operate the same, but read slightly\ndifferently in code.\n\nThis rule recommends using the `toBe` matcher in these situations, as\nit forms the most grammatically natural sentence. For `null`,\n`undefined`, and `NaN` this rule recommends using their specific `toBe`","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs#L23-L59","documentation":"Warning from the oxlint `jest/prefer-to-be` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs:41). The rule's run implementation checks `first_matcher_arg.is_nan()`; when an equality matcher is called with the literal `NaN`, it suggests `toBeNaN()`, which gives a precise failure message instead of a confusing deep-equality diff.","triggerScenarios":"`expect(value).toBe(NaN)`, `expect(value).toEqual(NaN)`, or `expect(value).toStrictEqual(NaN)` - the matcher argument is the `NaN` identifier.","commonSituations":"Numeric-parsing tests such as `expect(Number('abc')).toEqual(NaN)`; geometry or financial code returning NaN on invalid input; suites newly linted by the jest plugin.","solutions":["Rewrite as `expect(value).toBeNaN()`.","Remember `toEqual(NaN)` already behaves like `toBeNaN`, so the swap is semantics-preserving - no test rework beyond the matcher name.","Suppress with `// oxlint-disable-next-line jest/prefer-to-be` if you must keep the original."],"exampleFix":"// before\nexpect(Number('abc')).toEqual(NaN);\n\n// after\nexpect(Number('abc')).toBeNaN();","handlingStrategy":"validation","validationCode":"// rg -n \"\\.toBe\\(NaN\\)|\\.toEqual\\(NaN\\)\" tests/ -t ts -t js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember Number.isNaN assertions map to toBeNaN in jest/vitest","Keep the jest plugin's recommended rules active in .oxlintrc.json"],"tags":["jest","vitest","oxlint","matcher","nan"],"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-14T05:17:10.506Z"}