vitest/valid-expect-in-promise
January 2, 2026 ยท View on GitHub
๐ 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])
})