Skip to main content
Version: v1

MockLogger Class

The MockLogger records events sent to it, and then can walk back over those events searching for a set of expected events to match against the logged events.

Signature​

export declare class MockLogger extends TelemetryLogger implements ITelemetryLogger

Extends: TelemetryLogger

Implements: ITelemetryLogger

Constructors​

ConstructorDescription
(constructor)()Constructs a new instance of the MockLogger class

Properties​

PropertyTypeDescription
eventsITelemetryBaseEvent[]

Methods​

MethodReturn TypeDescription
assertMatch(expectedEvents, message)voidAsserts that matchEvents is true, and prints the actual/expected output if not
assertMatchAny(expectedEvents, message)voidAsserts that matchAnyEvent is true, and prints the actual/expected output if not
clear()void
matchAnyEvent(expectedEvents)booleanSearch events logged since the last time matchEvents was called, looking for any of the given expected events.
matchEvents(expectedEvents)booleanSearch events logged since the last time matchEvents was called, looking for the given expected events in order.
send(event)void

Constructor Details​

(constructor)​

Constructs a new instance of the MockLogger class

Signature​

constructor();

Property Details​

events​

Signature​

events: ITelemetryBaseEvent[];

Type: ITelemetryBaseEvent[]

Method Details​

assertMatch​

Asserts that matchEvents is true, and prints the actual/expected output if not

Signature​

assertMatch(expectedEvents: Omit<ITelemetryBaseEvent, "category">[], message?: string): void;

Parameters​

ParameterModifiersTypeDescription
expectedEventsOmit<ITelemetryBaseEvent, "category">[]
messageoptionalstring

assertMatchAny​

Asserts that matchAnyEvent is true, and prints the actual/expected output if not

Signature​

assertMatchAny(expectedEvents: Omit<ITelemetryBaseEvent, "category">[], message?: string): void;

Parameters​

ParameterModifiersTypeDescription
expectedEventsOmit<ITelemetryBaseEvent, "category">[]
messageoptionalstring

clear​

Signature​

clear(): void;

matchAnyEvent​

Search events logged since the last time matchEvents was called, looking for any of the given expected events.

Signature​

matchAnyEvent(expectedEvents: Omit<ITelemetryBaseEvent, "category">[]): boolean;

Parameters​

ParameterTypeDescription
expectedEventsOmit<ITelemetryBaseEvent, "category">[]events that are expected to appear in the recorded log. These event objects may be subsets of the logged events. Note: category is ommitted from the type because it's usually uninteresting and tedious to type.

Returns​

if any of the expected events is found.

Return type: boolean

matchEvents​

Search events logged since the last time matchEvents was called, looking for the given expected events in order.

Signature​

matchEvents(expectedEvents: Omit<ITelemetryBaseEvent, "category">[]): boolean;

Parameters​

ParameterTypeDescription
expectedEventsOmit<ITelemetryBaseEvent, "category">[]events in order that are expected to appear in the recorded log. These event objects may be subsets of the logged events. Note: category is ommitted from the type because it's usually uninteresting and tedious to type.

Returns​

Return type: boolean

send​

Signature​

send(event: ITelemetryBaseEvent): void;

Parameters​

ParameterTypeDescription
eventITelemetryBaseEvent