For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/testing-library/fire-event.md.

fireEvent

Fires a Lynx event at an element, which runs the handlers a device would, such as (bindtap). import { fireEvent, waitForUpdate } from '@blotch/angular-lynx-testing-library';

Usage

fireEvent.tap(getByRole('button', { name: 'Add one' }));
await waitForUpdate();

expect(getByText('Taps: 1')).toBeTruthy();

fireEvent(element, event)

fireEvent(element: Element, event: Event): boolean;
fireEvent.tap(element: Element, init?: Record<string, unknown>): boolean;
// … one method per event in the Event reference

Fires a Lynx event at element. There's one method per event: the Event reference lists them, and the binding each one runs.

fireEvent doesn't render

The handler runs before fireEvent returns, so a spy or a signal you read directly already shows the change.

Angular renders the result in a change detection it schedules for after the current task. Await waitForUpdate() before checking the rendered output.

Arguments

ArgumentDescription
initProperties to set on the event. { detail: { value: 'hi' } } arrives as $event.detail.value
init.bubblesOverrides whether the event goes up to the page. { bubbles: false } keeps a tap on element
init.eventTypeFires at one kind of handler on element alone, such as 'catchEvent' for its (catch*) handler
eventAn event of type '<eventType>:<name>', for an event without a method. See below

For an event without a method, pass an event such as new Event('bindEvent:change'). A CustomEvent's detail arrives as $event.detail.

Bubbling

  • Touch, mouse and key events bubble. They go from element up to the page, as on a device, so a tap on a row reaches its card's (click).
  • A (catch*) handler stops them. So does one that calls $event.stopPropagation(). Either runs, then stops the event there.
  • (capture-*) handlers run first, from the page down.
  • Other events stay put. Events such as scroll and input run only element's own handler.

eventMap

const eventMap: Record<string, { defaultInit: { bubbles?: boolean } }>;

The events that fireEvent has a method for, keyed by event name. defaultInit.bubbles is true for the events that go up to the page.