{"record":{"id":"2674f0cf037c5dfd","repo":"oxc-project/oxc","slug":"prefer-await-expect-resolves-over-expect-a","errorCode":null,"errorMessage":"Prefer `await expect(...).resolves` over `expect(await ...)` syntax.","messagePattern":"Prefer `await expect\\(\\.\\.\\.\\)\\.resolves` over `expect\\(await \\.\\.\\.\\)` syntax\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_resolves.rs","lineNumber":14,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    context::LintContext,\n    utils::{PossibleJestNode, parse_expect_jest_fn_call},\n};\n\nfn expect_resolves(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `await expect(...).resolves` over `expect(await ...)` syntax.\")\n        .with_help(\"Use `await expect(...).resolves` instead\")\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r#\"### What it does\n\nPrefer `await expect(...).resolves` over `expect(await ...)` when testing\npromises.\n\n### Why is this bad?\n\nWhen working with promises, there are two primary ways you can test the\nresolved value:\n\n1. use the `resolve` modifier on `expect`\n(`await expect(...).resolves.<matcher>` style)\n2. `await` the promise and assert against its result\n(`expect(await ...).<matcher>` style)","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_resolves.rs#L1-L32","documentation":"This is the oxlint `prefer-expect-resolves` rule (jest/vitest plugin). When you `await` inside the expect argument — `expect(await getUser())` — the promise settles before expect sees it, so a rejected promise throws an ordinary (unmatched, less descriptive) error and `.rejects` handling is impossible. The rule requires the `await expect(...).resolves` form where Jest itself awaits and reports the settled value.","triggerScenarios":"An expect() call whose single Argument contains an `await` expression — `expect(await promise)` — typically followed by matchers like `.toBe`, `.toEqual`.","commonSituations":"Habitual `await` before passing to expect; refactoring async code where the await got pulled into the call; teams unaware of the `.resolves` matcher.","solutions":["Move the await: `await expect(getUser()).resolves.toEqual(user)`.","For failure paths, use `await expect(getUser()).rejects.toThrow('not found')`.","Keep `expect(await x)` only if you deliberately want the throw to escape the matcher (rare; prefer not to)."],"exampleFix":"// before\nit('gets user', async () => {\n  expect(await getUser(1)).toEqual({ id: 1 });\n});\n\n// after\nit('gets user', async () => {\n  await expect(getUser(1)).resolves.toEqual({ id: 1 });\n});","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"jest/prefer-expect-resolves\": \"error\" } }\n\nnpx oxlint tests/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Memorize the two shapes: `await expect(p).resolves.x` and `await expect(p).rejects.x`.","Never place `await` between `expect(` and its argument.","Enable the rule so promise tests keep useful rejection diagnostics."],"tags":["jest","vitest","oxlint","testing","async-await","promises","static-analysis"],"backgroundTag":"async-assertion-pattern","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"}