{"record":{"id":"43566293fb4983c0","repo":"oxc-project/oxc","slug":"suggest-using-tostrictequal","errorCode":null,"errorMessage":"Suggest using `toStrictEqual()`.","messagePattern":"Suggest using `toStrictEqual\\(\\)`\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_strict_equal.rs","lineNumber":10,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    utils::{PossibleJestNode, parse_expect_jest_fn_call},\n};\n\nfn use_to_strict_equal(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Suggest using `toStrictEqual()`.\")\n        .with_help(\"Use `toStrictEqual()` instead\")\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nThis rule triggers a warning if `toEqual()` is used to assert equality.\n\n### Why is this bad?\n\nThe `toEqual()` matcher performs a deep equality check but ignores\n`undefined` values in objects and arrays. This can lead to false\npositives where tests pass when they should fail. `toStrictEqual()`\nprovides more accurate comparison by checking for `undefined` values.\n\n### Examples\n\nExamples of **incorrect** code for this rule:","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_strict_equal.rs#L1-L28","documentation":"This warning comes from the oxlint `jest/prefer-strict-equal` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/prefer_strict_equal.rs:10). It fires when a test uses `toEqual()` for deep equality. The rule's rationale is that `toEqual()` ignores `undefined` properties in objects and arrays, which can produce passing tests that should fail, while `toStrictEqual()` also checks type and class equality.","triggerScenarios":"An `expect(...)` call chained with the `toEqual()` matcher on an object, array, or class instance, e.g. `expect(actual).toEqual(expected)`. The rule is part of the jest/vitest plugin in oxlint, so it fires when that plugin is enabled (e.g. `oxlint --jest` or a `.oxlintrc.json` with the jest plugin and this rule turned on).","commonSituations":"Teams migrating from ESLint's eslint-plugin-jest to oxlint and re-enabling stricter preset rules; test suites that assert on partially-built objects where `undefined` vs missing keys matters; CI pipelines that run `oxlint` with `--deny-warnings` so this warning fails the build.","solutions":["Replace `toEqual(...)` with `toStrictEqual(...)` where type-strict equality is intended: `expect(actual).toStrictEqual(expected)`.","Re-run the tests to confirm they still pass; if they now fail, the failure is the exact `undefined`/type mismatch the rule is warning about - fix the expectation or the production data.","If the looser `toEqual` semantics are intentional for that assertion, suppress inline with `// oxlint-disable-next-line jest/prefer-strict-equal` (or `/* eslint-disable */`-style comment your config maps).","If the whole repo wants loose equality, disable the rule in `.oxlintrc.json`: `\"rules\": { \"jest/prefer-strict-equal\": \"off\" }`."],"exampleFix":"// before\nexpect(result).toEqual({ id: 1 });\n\n// after\nexpect(result).toStrictEqual({ id: 1 });","handlingStrategy":"validation","validationCode":"// Pre-commit scan: find loose equality on objects before lint runs\n// rg -n \"\\.toEqual\\(\" --type ts tests/ | rg -v \"toStrictEqual\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on toStrictEqual in an .oxlintrc.json preset so the rule runs on every commit","Add oxlint to a pre-commit hook so loose matchers are caught before CI","Codemod once with `oxlint --fix` where fixers exist, then enforce deny-warnings"],"tags":["jest","vitest","oxlint","matcher","equality"],"backgroundTag":"jest-toequal-strictness","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"}