{"record":{"id":"975e1d75dfa1fa32","repo":"oxc-project/oxc","slug":"use-tobe-when-expecting-primitive-literals","errorCode":null,"errorMessage":"Use `toBe` when expecting primitive literals.","messagePattern":"Use `toBe` when expecting primitive literals\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs","lineNumber":17,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, CallExpression, Expression},\n};\nuse 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.\")","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs#L1-L35","documentation":"Warning from the oxlint `jest/prefer-to-be` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_be.rs:17). It fires when an equality matcher (`toBe`, `toEqual`, `toStrictEqual`) is called with a primitive literal such as a number, string, or boolean. All equality matchers behave identically for primitives, so the rule recommends `toBe` as the most natural reading.","triggerScenarios":"`expect(value).toEqual(5)`, `expect(getMessage()).toStrictEqual('hello world')`, or `expect(loadMessage()).resolves.toEqual('hello world')` - i.e. an `expect(...)` call whose matcher (any of toBe/toEqual/toStrictEqual) receives a primitive literal argument. The rule is a single implementation shared by the jest and vitest oxlint plugins.","commonSituations":"Codebases that standardized on `toEqual` everywhere and then enabled the jest plugin's recommended preset; copy-pasted assertions; migration from eslint-plugin-jest where this rule (added in v25.0.0+) was already surfacing.","solutions":["Change the matcher to `toBe`: `expect(value).not.toBe(5)`, `expect(getMessage()).toBe('hello world')`.","Run `oxlint --fix` if the rule ships a fixer in your oxlint version, otherwise apply the rename manually.","Suppress the single line with `// oxlint-disable-next-line jest/prefer-to-be` when the literal-style assertion is deliberate.","Turn the rule off repo-wide in `.oxlintrc.json` if the team prefers `toEqual` uniformly."],"exampleFix":"// before\nexpect(value).not.toEqual(5);\nexpect(getMessage()).toStrictEqual('hello world');\n\n// after\nexpect(value).not.toBe(5);\nexpect(getMessage()).toBe('hello world');","handlingStrategy":"validation","validationCode":"// rg -n \"\\.toEqual\\((?:true|false|\\d+|')\" tests/ -t ts","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt the jest recommended preset in .oxlintrc.json so primitives-to-toBe is enforced continuously","Run `oxlint --fix` on legacy directories before enabling --deny-warnings","Teach the convention: primitives -> toBe, objects -> toEqual/toStrictEqual, null/undefined/NaN -> dedicated matchers"],"tags":["jest","vitest","oxlint","matcher","style"],"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"}