> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# 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

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

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

## `fireEvent(element, event)`

```typescript
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](/api/testing-library/event-reference.md) lists them, and the binding each one runs.

:::warning 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()`](/api/testing-library/render.md#waitforupdate) before checking the rendered output.
:::

### Arguments

| Argument         | Description                                                                                        |
| ---------------- | -------------------------------------------------------------------------------------------------- |
| `init`           | Properties to set on the event. `{ detail: { value: 'hi' } }` arrives as `$event.detail.value`     |
| `init.bubbles`   | Overrides whether the event goes up to the page. `{ bubbles: false }` keeps a tap on `element`     |
| `init.eventType` | Fires at one kind of handler on `element` alone, such as `'catchEvent'` for its `(catch*)` handler |
| `event`          | An 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`

```typescript
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.

## Related

- [Event reference](/api/testing-library/event-reference.md)
- [Testing patterns](/guide/testing/patterns.md)
- [`render()` and `waitForUpdate()`](/api/testing-library/render.md)
- [Handling taps and events](/guide/elements/event-handling.md)
