Soundorv0.13.0

user.pointer

Moves the mouse and presses its buttons step by step: drags, held buttons, secondary clicks.

await user.pointer(actions: PointerAction | PointerAction[]): Promise<void>;

interface PointerAction {
  target?: NodeTarget; // the node; the previous one when omitted
  keys?: string;       // '[MouseLeft]', '[MouseLeft>]', '[/MouseLeft]', also MouseRight, MouseMiddle
  clientX?: number;    // and clientY, offsetX, offsetY, modifiers…
}

Each action moves the pointer to its target, then presses, holds or releases a button when keys says so. A drag is a press held, moves, and a release:

const knob = screen.getByRole('adjustable', { name: 'Gain' });
await user.pointer({ target: knob, keys: '[MouseLeft>]', clientY: 40 });
await user.pointer({ target: knob, clientY: 32 });
await user.pointer({ target: knob, keys: '[/MouseLeft]', clientY: 32 });
keysWhat it does
[MouseLeft]Presses and releases the button.
[MouseLeft>]Presses it, and keeps it down.
[/MouseLeft]Releases it.
(none)Moves only.

MouseRight (a secondary click: onContextMenu) and MouseMiddle work the same.

Good to know

  • Targets are explicit: a test has no layout, so nothing can be hit by position. The first action needs a target; later ones keep it.
  • Coordinates are the event's: give clientX/clientY (or offsetX/ offsetY) that the code under test reads, a drag's distance say.
  • Capture is implicit: while a button is down, the pressed node gets the moves, wherever they go, until the last button is released.
  • A mouse only: pen and touch events go through fireEvent.

On this page