oxc-project/oxc · error · OxcDiagnostic
`expect.{member_name}` must be awaited or returned as the la
Error message
`expect.{member_name}` must be awaited or returned as the last expression What it means
Emitted by the vitest/require-awaited-expect-poll rule when a poll-based expectation is awaited/returned but is not the last expression of its block, so the test continues after the poll completes. The rule requires poll assertions to be final so no assertions execute after an await that may skip them.
Source
Thrown at crates/oxc_linter/src/rules/vitest/require_awaited_expect_poll.rs:22
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{
AstNode,
context::LintContext,
rule::Rule,
rules::PossibleJestNode,
utils::{KnownMemberExpressionProperty, parse_expect_and_typeof_vitest_fn_call},
};
fn require_awaited_expect_poll_diagnostic(span: Span, member_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("`expect.{member_name}` must be awaited or returned"))
.with_help(format!("Add `await` to the `expect.{member_name}` call."))
.with_label(span)
}
fn require_awaited_expect_poll_return_diagnostic(span: Span, member_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("`expect.{member_name}` must be awaited or returned as the last expression"))
.with_help(format!("Add `await` to the `expect.{member_name}` call or move it to the last position in the sequence."))
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct RequireAwaitedExpectPoll;
declare_oxc_lint!(
/// ### What it does
///
/// This rule ensures that promises returned by `expect.poll` and `expect.element` calls are handled properly.
///
/// ### Why is this bad?
///
/// `expect.poll` and `expect.element` return promises. If not awaited or returned,
/// the test completes before the assertion resolves, meaning the test will pass
/// regardless of whether the assertion succeeds or fails.
///View on GitHub (pinned to e1e7af627c)
Solutions
- Move the awaited `expect.poll()` assertion to be the last statement of the test/callback body
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/vitest/require_awaited_expect_poll.rs:22 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/a9033054a5cf22f1.
Report an issue: GitHub.