Appearance
Function: hover()
ts
function hover<T>(
ctx: Context,
selector: string,
fn: () => Promise<T>): Promise<T>;Defined in: src/mouse/index.ts:243
Hover over an element and run a callback.
Dispatches mouse and focus events to simulate a hover. Runs the provided callback while the element is hovered, then dispatches leave events.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | Context | Context object. |
selector | string | CSS selector for the element to hover. |
fn | () => Promise<T> | Async callback to run while the element is hovered. |
Returns
Promise<T>
The value returned by fn.
Example
ts
// Hover over a nav menu to reveal a dropdown, then click a sub-item
await hover(ctx, 'nav[id="main-menu"]', async () => {
await click(ctx, 'a[data-item="settings"]');
});