Skip to content

Commit e0b63a2

Browse files
committed
test: wait for transition
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 96b85a6 commit e0b63a2

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/dialogs.spec.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { cleanup, findByRole, fireEvent, getByLabelText, getByRole } from '@testing-library/vue'
7-
import { afterEach, expect, test } from 'vitest'
6+
import { findByRole, fireEvent, getByLabelText, getByRole } from '@testing-library/vue'
7+
import { expect, test } from 'vitest'
88
import { showConfirmation } from './dialogs.ts'
99

10-
afterEach(cleanup)
10+
async function waitForTransition() {
11+
await new Promise((r) => window.setTimeout(r, 250))
12+
}
1113

1214
test('Show confirmation dialog', async () => {
1315
const promise = showConfirmation({
@@ -16,6 +18,8 @@ test('Show confirmation dialog', async () => {
1618
})
1719

1820
const dialog = await findByRole(document.documentElement, 'dialog')
21+
await waitForTransition()
22+
1923
expect(dialog).toBeInstanceOf(HTMLElement)
2024

2125
expect(getByLabelText(document.documentElement, 'Dialog name')).toBe(dialog)
@@ -38,8 +42,10 @@ test('show confirmation dialog with reject', async () => {
3842
})
3943

4044
const dialog = await findByRole(document.documentElement, 'dialog')
41-
const confirm = getByRole(dialog, 'button', { name: 'My confirm' })
42-
const reject = getByRole(dialog, 'button', { name: 'My reject' })
45+
await waitForTransition()
46+
47+
const confirm = await findByRole(dialog, 'button', { name: 'My confirm' })
48+
const reject = await findByRole(dialog, 'button', { name: 'My reject' })
4349
expect(confirm).toBeInstanceOf(HTMLElement)
4450
expect(reject).toBeInstanceOf(HTMLElement)
4551
await fireEvent(reject, new MouseEvent('click', { bubbles: true }))
@@ -53,8 +59,9 @@ test('show confirmation dialog and close', async () => {
5359
})
5460

5561
const dialog = await findByRole(document.documentElement, 'dialog')
56-
const close = getByRole(dialog, 'button', { name: 'Close' })
57-
expect(close).toBeInstanceOf(HTMLElement)
62+
await waitForTransition()
63+
64+
const close = await findByRole(dialog, 'button', { name: 'Close' })
5865
await fireEvent(close, new MouseEvent('click', { bubbles: true }))
5966
await expect(promise).rejects.toThrowError('Dialog closed')
6067
})

vitest.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const testConfig = defineConfig({
99
test: {
1010
environment: 'happy-dom',
1111
coverage: {
12-
all: true,
1312
provider: 'v8',
1413
include: ['lib/**/*.ts', 'lib/*.ts'],
1514
exclude: ['lib/**/*.spec.ts'],

0 commit comments

Comments
 (0)