cljs-tlr.user-event

High-level user interaction simulation.

User events simulate real user behavior more accurately than cljs-tlr.events. For example, clicking an element will:

  1. Move pointer to element
  2. Fire mouseOver/mouseEnter events
  3. Fire mouseDown event
  4. Fire focus event (if focusable)
  5. Fire mouseUp event
  6. Fire click event

All functions return Promises and should be used with async testing patterns like (t/async done ...) or the cljs-tlr.async/async-test macro.

clear

(clear user element)

Clears an input or textarea element. Returns a Promise.

Selects all text and deletes it, simulating Ctrl+A followed by Delete.

click

(click user element)

Clicks an element. Returns a Promise.

Simulates the full click sequence: pointer move, mousedown, focus (if applicable), mouseup, and click.

copy

(copy user)

Copies selected text to clipboard. Returns a Promise.

cut

(cut user)

Cuts selected text to clipboard. Returns a Promise.

dbl-click

(dbl-click user element)

Double-clicks an element. Returns a Promise.

deselect-options

(deselect-options user element values)

Deselects options in a multi-select element. Returns a Promise.

hover

(hover user element)

Hovers pointer over an element. Returns a Promise.

keyboard

(keyboard user text)

Types using keyboard shortcuts and special keys. Returns a Promise.

Supports special key syntax:

  • {Enter} - Press Enter key
  • {Tab} - Press Tab key
  • {Escape} - Press Escape key
  • {Backspace} - Press Backspace
  • {Delete} - Press Delete
  • {ArrowLeft} - Press left arrow
  • {Shift>} - Hold Shift (release with {/Shift})
  • {Control>} - Hold Control
  • {Alt>} - Hold Alt

Example:

(keyboard user "{Shift>}hello{/Shift}") ; types HELLO

paste

(paste user)(paste user text)

Pastes from clipboard or provided text. Returns a Promise.

pointer

(pointer user actions)

Performs pointer actions. Returns a Promise.

Low-level API for complex pointer interactions. Accepts an action map or array of action maps with keys like :target, :keys, :offset, etc.

select-options

(select-options user element values)

Selects options in a select element. Returns a Promise.

Values can be a single value or array of values for multi-select.

setup

(setup)(setup opts)

Creates a new user-event instance with optional configuration.

Options map supports:

  • :delay - Delay between actions in ms (default: 0)
  • :pointer-events-check - Validate pointer-events CSS (default: true)
  • :skip-hover - Skip hover events before click (default: false)
  • :skip-click - Skip click events for type/select (default: false)

Returns a user object to pass to interaction functions.

Example:

(let [user (setup {:delay 100})]
  (-> (click user button)
      (.then #(type user input "hello"))))

tab

(tab user)(tab user opts)

Presses Tab to move focus. Returns a Promise.

Options:

  • :shift - Hold shift key (move backwards)

triple-click

(triple-click user element)

Triple-clicks an element. Returns a Promise.

Useful for selecting entire paragraphs of text.

type-text

(type-text user element text)

Types text into an element. Returns a Promise.

Simulates typing character by character, firing keydown, keypress, input, and keyup events for each character.

Example:

(-> (type-text user input "[email protected]")
    (.then #(is (= "[email protected]" (.-value input)))))

unhover

(unhover user element)

Moves pointer away from element. Returns a Promise.

upload

(upload user element files)

Uploads files to a file input. Returns a Promise.

Files should be File objects or an array of File objects.