Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1.16 KB

File metadata and controls

41 lines (29 loc) · 1.16 KB

vitest/no-unneeded-async-expect-function

📝 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()
})