test(document): replace 2 setTimeout sleeps in WhoWhenSection with vi.waitFor

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-11 17:38:09 +02:00
parent dedf2ab990
commit 96366463ab

View File

@@ -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 () => {