Skip to content
tai-kun's Vite+ Lint Plugins
Esc
↑↓navigate↵open⌘Jpreview
On this page

no-await-in-expect

Require `await expect(...).resolves` or `.rejects` instead of `expect(await ...)`.

  • Rule ID: tai-kun/no-await-in-expect
  • Auto-fix: Yes

Reports code that awaits a value inside expect(). Since expect(await ...) cannot assert a rejected promise with .rejects, it is rewritten to await expect(...).resolves or await expect(...).rejects.

Configuration

Add the rule to lint.rules in vite.config.ts to enable it.

"tai-kun/no-await-in-expect": "error",

Examples

Invalid

test("basic", async () => {
  expect(await run()).toBe(1);
});

Valid

test("basic", async () => {
  await expect(run()).resolves.toBe(1);
});

Notes

  • The auto-fix rewrites with .resolves. To assert a rejection, change it to .rejects manually.
  • For chains that already use .resolves / .rejects, the fix only removes the await.
  • No extra await is added when the expression is already awaited (e.g. await expect(await ...)).

Was this page helpful?