From 0e9d88eed42e81fdaf32f85f21b428294eb0c891 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 11 May 2026 17:38:09 +0200 Subject: [PATCH] test(document): replace 2 setTimeout sleeps in WhoWhenSection with vi.waitFor Co-Authored-By: Claude Opus 4.7 --- .../document/WhoWhenSection.svelte.test.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/frontend/src/lib/document/WhoWhenSection.svelte.test.ts b/frontend/src/lib/document/WhoWhenSection.svelte.test.ts index e65b5f1e..a48ac430 100644 --- a/frontend/src/lib/document/WhoWhenSection.svelte.test.ts +++ b/frontend/src/lib/document/WhoWhenSection.svelte.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, afterEach } from 'vitest'; +import { describe, it, expect, vi, afterEach } from 'vitest'; import { cleanup, render } from 'vitest-browser-svelte'; import WhoWhenSection from './WhoWhenSection.svelte'; @@ -12,12 +12,11 @@ describe('WhoWhenSection — date input behavior', () => { dateInput.value = '32.13'; dateInput.dispatchEvent(new Event('input', { bubbles: true })); - await new Promise((r) => setTimeout(r, 30)); - // Invalid → border-red-400 class - expect(dateInput.className).toContain('border-red-400'); - - const error = document.querySelector('#date-error'); - expect(error).not.toBeNull(); + await vi.waitFor(() => { + // Invalid → border-red-400 class + expect(dateInput.className).toContain('border-red-400'); + expect(document.querySelector('#date-error')).not.toBeNull(); + }); }); it('does not show the error before the user has typed', async () => { @@ -34,11 +33,12 @@ describe('WhoWhenSection — date input behavior', () => { dateInput.value = '15.03.2024'; dateInput.dispatchEvent(new Event('input', { bubbles: true })); - await new Promise((r) => setTimeout(r, 30)); - const hidden = document.querySelector( - 'input[name="documentDate"][type="hidden"]' - ) as HTMLInputElement; - expect(hidden.value).toBe('2024-03-15'); + await vi.waitFor(() => { + const hidden = document.querySelector( + 'input[name="documentDate"][type="hidden"]' + ) as HTMLInputElement; + expect(hidden.value).toBe('2024-03-15'); + }); }); it('renders the location input outside editMode with initialLocation', async () => {