Class: OutputTracker

OutputTracker(eventTarget, event)

Tracks output events.

This is one of the nullability patterns from James Shore's article on testing without mocks.

Example implementation of an event store:

async record(event) {
  // ...
  this.dispatchEvent(new CustomEvent(EVENT_RECORDED_EVENT, { detail: event }));
}

trackEventsRecorded() {
  return new OutputTracker(this, EVENT_RECORDED_EVENT);
}

Example usage:

const eventsRecorded = eventStore.trackEventsRecorded();
// ...
const data = eventsRecorded.data(); // [event1, event2, ...]

Constructor

new OutputTracker(eventTarget, event)

Creates a tracker for a specific event of an event target.

Parameters:
Name Type Description
eventTarget EventTarget

The event target to track.

event string

The event name to track.

Classes

OutputTracker

Members

data

Returns the tracked data.

Methods

clear() → {Array}

Clears the tracked data and returns the cleared data.

Returns:

The cleared data.

Type
Array

stop()

Stops tracking.

(static) create(eventTarget, event)

Creates a tracker for a specific event of an event target.

Parameters:
Name Type Description
eventTarget EventTarget

The event target to track.

event string

The event name to track.