# vitest/require-awaited-expect-poll

> Require `expect.poll` and `expect.element` assertions to be awaited or returned

`expect.poll` and `expect.element` retry until the assertion holds, so they return a promise. If you don't await or return it, the test doesn't wait for it and ends before the assertion has a result.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"vitest/require-awaited-expect-poll" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
import { expect, test } from "vitest";

test("shows the saved message", () => {
  expect.poll(() => status.text).toBe("Saved");
  expect.element(banner).toBeVisible();
});
```

Not reported:

{/* good */}
```js
import { expect, test } from "vitest";

test("shows the saved message", async () => {
  await expect.poll(() => status.text).toBe("Saved");
  await expect.element(banner).toBeVisible();
});

test("hides the spinner", () => {
  return expect.poll(() => spinner.hidden).toBe(true);
});
```

The `await` or `return` must be right in front of the assertion. An arrow function without braces and `Promise.all` are reported too:

{/* bad */}
```js
import { expect, test } from "vitest";

test("hides the spinner", () => expect.poll(() => spinner.hidden).toBe(true));
```

{/* bad */}
```js
import { expect, test } from "vitest";

test("saves both fields", async () => {
  await Promise.all([
    expect.poll(() => title.saved).toBe(true),
    expect.poll(() => body.saved).toBe(true),
  ]);
});
```
