fireEvent
fireEvent
is a method on NgtTestBed
that allows us to fire events on any element in the scene graph.
fireEvent(element, eventName, eventData)
fireEvent
accepts three arguments:
element
is the element to fire the event oneventName
is the name of the event to fire. Must be events that are supported by Angular Three events system.eventData
is an optional object that contains the event data
fireEvent.setAutoDetectChanges(auto: boolean)
After firing an event, a Change Detection is needed with fixture.detectChanges()
to flush any changes that may have occurred (e.g: signal state changes).
fireEvent
does this automatically, but we can disable it by calling fireEvent.setAutoDetectChanges(false)
.
Example Scenario
For this example, we will use fireEvent
to fire pointerover
, pointerout
, and click
events on the cube
and assert the cube’s state after each event.
Last but not least, we will use advance
to test the animations.