Improve this Doc View Source

## Overview

This is a global (window) function that is only available when the `ngMock` module is included.

It can be used to trigger a native browser event on an element, which is useful for unit testing.

## Usage

`browserTrigger(element, [eventType], [eventData]);`

### Arguments

Param | Type | Details
--- | --- | ---
element | Object | Either a wrapped jQuery/jqLite node or a DOMElement
eventType (optional) | string | Optional event type. If none is specified, the function tries to determine the right event type for the element, e.g. `change` for `input[text]`.

eventData
(optional)

Object

An optional object which contains additional event data that is used when creating the event:

- `bubbles`: Event.bubbles. Not applicable to all events.

- `cancelable`: Event.cancelable. Not applicable to all events.

- `charcode`: charCode for keyboard events (keydown, keypress, and keyup).

- `elapsedTime`: the elapsedTime for TransitionEvent and AnimationEvent.

- `keycode`: keyCode for keyboard events (keydown, keypress, and keyup).

- `keys`: an array of possible modifier keys (ctrl, alt, shift, meta) for MouseEvent and keyboard events (keydown, keypress, and keyup).

- `relatedTarget`: the relatedTarget for MouseEvent.

- `which`: which for keyboard events (keydown, keypress, and keyup).

- `x`: x-coordinates for MouseEvent and TouchEvent.

- `y`: y-coordinates for MouseEvent and TouchEvent.