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:
@@ -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 { cleanup, render } from 'vitest-browser-svelte';
|
||||||
import WhoWhenSection from './WhoWhenSection.svelte';
|
import WhoWhenSection from './WhoWhenSection.svelte';
|
||||||
|
|
||||||
@@ -12,12 +12,11 @@ describe('WhoWhenSection — date input behavior', () => {
|
|||||||
dateInput.value = '32.13';
|
dateInput.value = '32.13';
|
||||||
dateInput.dispatchEvent(new Event('input', { bubbles: true }));
|
dateInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 30));
|
await vi.waitFor(() => {
|
||||||
// Invalid → border-red-400 class
|
// Invalid → border-red-400 class
|
||||||
expect(dateInput.className).toContain('border-red-400');
|
expect(dateInput.className).toContain('border-red-400');
|
||||||
|
expect(document.querySelector('#date-error')).not.toBeNull();
|
||||||
const error = document.querySelector('#date-error');
|
});
|
||||||
expect(error).not.toBeNull();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not show the error before the user has typed', async () => {
|
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.value = '15.03.2024';
|
||||||
dateInput.dispatchEvent(new Event('input', { bubbles: true }));
|
dateInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 30));
|
await vi.waitFor(() => {
|
||||||
const hidden = document.querySelector(
|
const hidden = document.querySelector(
|
||||||
'input[name="documentDate"][type="hidden"]'
|
'input[name="documentDate"][type="hidden"]'
|
||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
expect(hidden.value).toBe('2024-03-15');
|
expect(hidden.value).toBe('2024-03-15');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the location input outside editMode with initialLocation', async () => {
|
it('renders the location input outside editMode with initialLocation', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user