Skip to content

Commit a6c9771

Browse files
authored
test: fix async assertion warning (#6959)
1 parent 021944c commit a6c9771

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

test/core/test/jest-expect.test.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AssertionError } from 'node:assert'
33
import { stripVTControlCharacters } from 'node:util'
44
import { generateToBeMessage } from '@vitest/expect'
55
import { processError } from '@vitest/utils/error'
6-
import { describe, expect, it, vi } from 'vitest'
6+
import { beforeAll, describe, expect, it, vi } from 'vitest'
77

88
class TestError extends Error {}
99

@@ -917,14 +917,14 @@ describe('async expect', () => {
917917
await expect((async () => {
918918
throw new Error('err')
919919
})()).rejects.toThrow('err')
920-
expect((async () => {
920+
await expect((async () => {
921921
throw new TestError('error')
922922
})()).rejects.toThrow(TestError)
923923
const err = new Error('hello world')
924-
expect((async () => {
924+
await expect((async () => {
925925
throw err
926926
})()).rejects.toThrow(err)
927-
expect((async () => {
927+
await expect((async () => {
928928
throw new Error('message')
929929
})()).rejects.toThrow(expect.objectContaining({
930930
message: expect.stringContaining('mes'),
@@ -1011,6 +1011,12 @@ describe('async expect', () => {
10111011
})
10121012

10131013
describe('promise auto queuing', () => {
1014+
// silence warning
1015+
beforeAll(() => {
1016+
const spy = vi.spyOn(console, 'warn').mockImplementation(() => {})
1017+
return () => spy.mockRestore()
1018+
})
1019+
10141020
it.fails('fails', () => {
10151021
expect(new Promise((resolve, reject) => setTimeout(reject, 500)))
10161022
.resolves

test/core/test/mocked.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ describe('default exported classes', () => {
129129
})
130130
})
131131

132-
test('async functions should be mocked', () => {
132+
test('async functions should be mocked', async () => {
133133
expect(asyncFunc()).toBeUndefined()
134134
expect(vi.mocked(asyncFunc).mockResolvedValue).toBeDefined()
135135
vi.mocked(asyncFunc).mockResolvedValue('foo')
136-
expect(asyncFunc()).resolves.toBe('foo')
136+
await expect(asyncFunc()).resolves.toBe('foo')
137137
})
138138

139139
function getError(cb: () => void): string {

test/core/test/snapshot-file.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ describe('snapshots', () => {
1313
for (const [path, file] of Object.entries(files)) {
1414
test(path, async () => {
1515
const entries = JSON.parse(await file()) as any[]
16-
expect(entries.map(i => objectToCSS(i[0], i[1])).join('\n'))
16+
await expect(entries.map(i => objectToCSS(i[0], i[1])).join('\n'))
1717
.toMatchFileSnapshot(path.replace('input.json', 'output.css'))
1818
})
1919
}
2020
})
2121

22-
test('handle empty file', () => {
23-
expect('').toMatchFileSnapshot('./fixtures/snapshot-empty.txt')
22+
test('handle empty file', async () => {
23+
await expect('').toMatchFileSnapshot('./fixtures/snapshot-empty.txt')
2424
})

test/core/test/wait.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, expect, test, vi } from 'vitest'
33
describe('waitFor', () => {
44
describe('options', () => {
55
test('timeout', async () => {
6-
expect(async () => {
6+
await expect(async () => {
77
await vi.waitFor(() => {
88
return new Promise((resolve) => {
99
setTimeout(() => {
@@ -125,7 +125,7 @@ describe('waitFor', () => {
125125
describe('waitUntil', () => {
126126
describe('options', () => {
127127
test('timeout', async () => {
128-
expect(async () => {
128+
await expect(async () => {
129129
await vi.waitUntil(() => {
130130
return new Promise((resolve) => {
131131
setTimeout(() => {

0 commit comments

Comments
 (0)