Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.19 KB

File metadata and controls

51 lines (39 loc) · 1.19 KB

vitest/valid-expect-in-promise

📝 Require promises that have expectations in their chain to be valid.

💼⚠️ This rule is enabled in the ✅ recommended config. This rule warns in the 🌐 all config.

This rule flags any promises within the body of a test that include expectations that have either not been returned or awaited.

The following patterns is considered warning:

test('promise test', async () => {
  something().then((value) => {
    expect(value).toBe('red')
  })
})

test('promises test', () => {
  const onePromise = something().then((value) => {
    expect(value).toBe('red')
  })
  const twoPromise = something().then((value) => {
    expect(value).toBe('blue')
  })

  return Promise.any([onePromise, twoPromise])
})

The following pattern is not warning:

test('promise test', async () => {
  await something().then((value) => {
    expect(value).toBe('red')
  })
})

test('promises test', () => {
  const onePromise = something().then((value) => {
    expect(value).toBe('red')
  })
  const twoPromise = something().then((value) => {
    expect(value).toBe('blue')
  })

  return Promise.all([onePromise, twoPromise])
})