@augment-vir/test
Version:
A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.
18 lines (17 loc) • 726 B
JavaScript
import { assert } from '@augment-vir/assert';
import { clickElement } from './click-element.js';
import { waitForAnimationFrame } from './symlinked/animation-frame.js';
import { isElementFocused } from './symlinked/element-focus.js';
export async function focusElement(element, maxAttemptCount = 20) {
let attempts = 0;
while (!isElementFocused(element) && attempts < maxAttemptCount) {
++attempts;
if (!isElementFocused(element)) {
await clickElement(element);
}
if (!isElementFocused(element)) {
await waitForAnimationFrame();
}
}
assert.isBelow(attempts, maxAttemptCount, `Tried ${maxAttemptCount} times to focus the given input element.`);
}