{"record":{"id":"07606644c22b4d5a","repo":"oxc-project/oxc","slug":"suggest-using-tocontain","errorCode":null,"errorMessage":"Suggest using `toContain()`.","messagePattern":"Suggest using `toContain\\(\\)`\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_contain.rs","lineNumber":18,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, CallExpression, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_ecmascript::{ToBoolean, WithoutGlobalReferenceInformation};\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    utils::{\n        KnownMemberExpressionParentKind, PossibleJestNode, is_equality_matcher,\n        parse_expect_jest_fn_call,\n    },\n};\n\nfn use_to_contain(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Suggest using `toContain()`.\").with_label(span)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nIn order to have a better failure message, `toContain()` should be used upon\nasserting expectations on an array containing an object.\n\n### Why is this bad?\n\nThis rule triggers a warning if `toBe()`, `toEqual()` or `toStrictEqual()` is\nused to assert object inclusion in an array\n\n### Examples\n\nExamples of **incorrect** code for this rule:\n```javascript\nexpect(a.includes(b)).toBe(true);\nexpect(a.includes(b)).not.toBe(true);","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_contain.rs#L1-L36","documentation":"Warning from the oxlint `jest/prefer-to-contain` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/prefer_to_contain.rs:18). The rule inspects `expect()` calls whose argument is an `includes(...)` call and whose matcher is an equality matcher (`toBe`/`toEqual`/`toStrictEqual`) with a boolean literal; it recommends `toContain()`, whose failure output shows the actual array contents.","triggerScenarios":"`expect(arr.includes(item)).toBe(true)`, `expect(arr.includes(item)).toEqual(false)`, or `expect(list.includes(x)).not.toBe(true)` - i.e. an equality matcher applied to the boolean result of `Array.prototype.includes`. The implementation uses `oxc_ecmascript::ToBoolean` (with `WithoutGlobalReferenceInformation`) to recognize the boolean-literal argument.","commonSituations":"Developers unfamiliar with `toContain` asserting membership the manual way; refactors of loops that used `indexOf(...) !== -1`; CI running oxlint with the jest plugin after migration from ESLint.","solutions":["Rewrite the assertion to move the array into `expect` and use `toContain`: `expect(arr).toContain(item)`.","For negative membership use `expect(arr).not.toContain(item)`.","Suppress inline with `// oxlint-disable-next-line jest/prefer-to-contain` when asserting on the boolean itself is the point (e.g. testing an `includes` polyfill)."],"exampleFix":"// before\nexpect(allowedUsers.includes('alice')).toBe(true);\n\n// after\nexpect(allowedUsers).toContain('alice');","handlingStrategy":"validation","validationCode":"// rg -n \"\\.includes\\([^)]*\\)\\)\\.(toBe|toEqual|toStrictEqual)\\((true|false)\\)\" tests/ -t ts -t js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write membership assertions directly with toContain from the start","When reviewing, flag any expect() whose argument is an includes() call"],"tags":["jest","vitest","oxlint","matcher","array"],"backgroundTag":"jest-tocontain-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"}