{"record":{"id":"e42222f773490116","repo":"oxc-project/oxc","slug":"async-assertions-must-be-awaited","errorCode":null,"errorMessage":"Async assertions must be awaited.","messagePattern":"Async assertions must be awaited\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/valid_expect.rs","lineNumber":23,"sourceCode":"use oxc_semantic::ScopeId;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::FxHashSet;\nuse schemars::JsonSchema;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    utils::{\n        ExpectError, PossibleJestNode, collect_possible_jest_call_node, parse_expect_jest_fn_call,\n    },\n};\n\nfn valid_expect_diagnostic<S: Into<Cow<'static, str>>>(\n    x1: S,\n    x2: &'static str,\n    span3: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(x1).with_help(x2).with_label(span3)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nChecks that `expect()` is called correctly.\n\n### Why is this bad?\n\n`expect()` is a function that is used to assert values in tests.\nIt should be called with a single argument, which is the value to be tested.\nIf you call `expect()` with no arguments, or with more than one argument, it will not work as expected.\n\n### Examples\n\nExamples of **incorrect** code for this rule:\n```javascript\nexpect();\nexpect('something');","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/valid_expect.rs#L5-L41","documentation":"Diagnostic from the shared jest/vitest `valid-expect` rule (Message::AsyncMustBeAwaited). It fires when an assertion that resolves asynchronously — one using the `resolves`/`rejects` modifiers or a matcher listed in `asyncMatchers` config (default `toResolve`, `toReject`) — is left floating: neither awaited nor returned from the test. The process can exit before the assertion runs, producing false-green tests.","triggerScenarios":"The rule computes `should_be_awaited` when any modifier other than `not` is present or the matcher name is in `asyncMatchers`; if the parent is not an acceptable return/await node (and `alwaysAwait: true` also rejects bare `return`), the diagnostic fires. Examples: `expect(Promise.resolve(1)).resolves.toBe(1);` as a statement, or `it('x', () => { expect(p).toResolve(); })` without await/return.","commonSituations":"Migrating callback-style tests to async, vitest extension matchers (`toResolve`/`toReject` from @vitest/eslint-plugin or jest-extended), and teams enabling `alwaysAwait` in config so even `return expect(...)...` must become `await`.","solutions":["Add `await` in front of the assertion (the rule ships an autofix that also inserts `async` on the enclosing function when needed): `await expect(p).resolves.toBe(1);`.","Alternatively `return` the assertion from the test function — accepted unless `alwaysAwait` is enabled.","Enable `alwaysAwait: true` in the rule config to enforce awaiting everywhere, preventing return-based flakes.","Run `oxlint --fix` to apply the built-in await/async fix across the file."],"exampleFix":"// before\nit('resolves', () => {\n  expect(Promise.resolve(1)).resolves.toBe(1);\n});\n\n// after\nit('resolves', async () => {\n  await expect(Promise.resolve(1)).resolves.toBe(1);\n});","handlingStrategy":"validation","validationCode":"// fail CI when an async assertion is not awaited\n// rg -n \"^\\s*expect\\(.*\\)\\.(resolves|rejects)\\.\" --type ts src/\nconst { execSync } = require('child_process');\ntry {\n  execSync(\"rg '^\\\\s*expect\\\\(.*\\\\)\\\\.(resolves|rejects)\\\\.' src/ --type ts\", { stdio: 'pipe' });\n  console.error('floating async assertions found (missing await/return)');\n  process.exitCode = 1;\n} catch { /* rg exit 1 = no matches, good */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enable `alwaysAwait` in valid-expect config so even `return expect(...)` must be awaited.","Default to `async () => { await expect(p).resolves... }` whenever you type `resolves`/`rejects`/`toResolve`/`toReject`.","Run tests with vitest/jest `--detectOpenHandles`-style strictness; floating assertions often surface as premature process exit."],"tags":["jest","vitest","oxlint","testing","async","await","promise","valid-expect"],"backgroundTag":"async-assertion-not-awaited","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"}