import {act, fireEvent} from '@testing-library/react'; import {userEvent} from '@testing-library/user-event'; import {type EnterValueOptions} from '@wix/unidriver-core'; import {delay} from '@wix/unidriver-common'; export const enterValue = async (base: HTMLElement, value: string, options?: EnterValueOptions) => { const {disabled, readOnly, name, type} = base as HTMLInputElement; const shouldClear = options?.shouldClear ?? true; const delayMs = options?.delay ?? 0; if (disabled || readOnly) { return; } if (delayMs > 0) { let currentValue: string = shouldClear ? '' : 'value' in base ? String(base.value) : ''; for (const char of value) { currentValue += char; await act(async () => { fireEvent.change(base, {target: {name, type, value: currentValue}}); await delay(delayMs); }); } return; } await act(async () => { return shouldClear ? fireEvent.change(base, {target: {name, value}}) : userEvent.type(base, value); }); };