vitest/no-unneeded-async-expect-function

January 2, 2026 ยท View on GitHub

๐Ÿ“ Disallow unnecessary async function wrapper for expected promises.

๐Ÿ’ผโš ๏ธ This rule is enabled in the โœ… recommended config. This rule warns in the ๐ŸŒ all config.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

Rule Details

Disallow wrapping expect calls with unnecessary async functions when the awaited call can be passed directly. If the only statement inside the async wrapper is await someCall(), pass someCall() straight to expect instead.

Examples of incorrect code for this rule:

it('wrong1', async () => {
  await expect(async () => {
    await doSomethingAsync()
  }).rejects.toThrow()
})

it('wrong2', async () => {
  await expect(async function () {
    await doSomethingAsync()
  }).rejects.toThrow()
})

it('wrong3', async () => {
  await expect(async () => await doSomethingAsync()).rejects.toThrow()
})

Examples of correct code for this rule

it('right1', async () => {
  await expect(doSomethingAsync()).rejects.toThrow()
})