event_bus_mock

Allows to create mock implementations of EventBus, compatible to the "axEventBus" and "axGlobalEventBus" injections.

Contents

Module Members

Types

Module Members

create( options )

Creates a mock EventBus, compatible to the "axEventBus" injection of a widget.

If no custom tick-scheduler function is passed through the options, the returned event bus has a method flush, to synchronously deliver all pending as well as synchronously added events. It also has a method drainAsync` to asynchronously run event handlers to completion, including additional asynchronously published events.

Parameters
Property Type Description
options Object additional options
options.nextTick Object an alternative callback for scheduling the next event bus cycle (such as window.setTimeout)
options.errorHandler Object an alternative error handler, e.g. to inspect error conditions during test. By default, exceptions thrown by subscribers to the mock will be reported using window.console.error
Returns
Type Description
EventBusMock a fresh mock instance

Types

EventBusMock

extends EventBus

A mock version of EventBus.

Offers spied-upon version of the usual axEventBus methods, including a spy on the unsubscribe-callback returned by subscribe. Also has as a flush method for synchronous scheduling of events, and a drainAsync to asynchronously run event handlers to completion.

EventBusMock.flush undefined

Flushes all pending events and runs their subscriber callbacks. If new events are published synchronously from subscriber callbacks, these will also be processed.

This operation happens synchronously, so asynchronously triggered events (e.g. those published from a then handler) may not be processed.

EventBusMock.drainAsync()

Asynchronously flushes pending events and runs their subscriber callbacks. If new events are published synchronously from subscriber callbacks, these will also be processed. Additionally, if new events are published asynchronously but immediately (i.e. right after a call to Promise.resolve), they will be processed as well.

This operation happens asynchronously, so callers need to wait on the returned promise in order to observe the effects.

Returns
Type Description
Promise a promise that is resolved when all events have been processed, and no more have been scheduled