{"record":{"id":"fb5e22596aa90619","repo":"oxc-project/oxc","slug":"suggest-using-the-built-in-equality-matchers","errorCode":null,"errorMessage":"Suggest using the built-in equality matchers.","messagePattern":"Suggest using the built-in equality matchers\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_equality_matcher.rs","lineNumber":16,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, BinaryExpression, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::Span;\nuse oxc_syntax::operator::BinaryOperator;\n\nuse crate::{\n    context::LintContext,\n    fixer::{FixKind, RuleFixer},\n    utils::{ParsedExpectFnCall, PossibleJestNode, is_equality_matcher, parse_expect_jest_fn_call},\n};\n\nfn use_equality_matcher_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Suggest using the built-in equality matchers.\")\n        .with_help(\"Prefer using one of the equality matchers instead\")\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nJest has built-in matchers for expecting equality, which allow for more readable\ntests and error messages if an expectation fails.\n\n### Why is this bad?\n\nTesting equality expressions with generic matchers like `toBe(true)`\nmakes tests harder to read and understand. When tests fail, the error\nmessages are less helpful because they don't show what the actual values\nwere. Using specific equality matchers provides clearer test intent and\nbetter debugging information.\n\n### Examples","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_equality_matcher.rs#L1-L34","documentation":"This is the oxlint `prefer-equality-matcher` rule (jest/vitest plugin). It flags `expect(a === b).toBe(true)`-style assertions and offers an autofix (`FixKind` fixer is imported) that rewrites them to the built-in equality matchers `toEqual`/`toStrictEqual`/`toBe`. The generic boolean form produces the unhelpful failure message 'expected true to be false', while the equality matcher prints an actual value diff.","triggerScenarios":"The expect argument is a `BinaryOperator` equality comparison (`==`, `===`, `!=`, `!==`) and the matcher is one of `is_equality_matcher`: `toBe`, `toEqual`, or `toStrictEqual`, e.g. `expect(x == null).toBe(true)`.","commonSituations":"Developers coming from assert-style libraries (`assert.strictEqual`); guarding against null/undefined with `== null` wrapped in toBe(true); generated test scaffolds that mechanically wrap booleans.","solutions":["Apply the rule's autofix (oxlint `--fix`): `expect(a === b).toBe(true)` becomes `expect(a).toBe(b)` (or toEqual for structural equality).","For negated comparisons, flip the matcher: `expect(a !== b).toBe(true)` → `expect(a).not.toBe(b)`.","For loose equality `== null`, prefer Jest's dedicated matchers: `expect(x).toBeNull()` / `toBeUndefined()` / `toBeDefined()`."],"exampleFix":"// before\nexpect(cart.total === 100).toBe(true);\n\n// after\nexpect(cart.total).toBe(100);","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"jest/prefer-equality-matcher\": \"error\" } }\n\nnpx oxlint --fix tests/  # autofix rewrites boolean equality assertions","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never wrap a comparison in toBe(true/false); assert the operands directly with toBe/toEqual.","Run `oxlint --fix` once on legacy suites to bulk-convert existing occurrences.","For null checks use the dedicated toBeNull/toBeUndefined/toBeDefined matchers."],"tags":["jest","vitest","oxlint","testing","assertions","equality","autofix","static-analysis"],"backgroundTag":"boolean-equality-assertion","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"}