Skip to main content

reporting.mocks

Helper functions to facilitate two-way communication when writing tests for your extension.

closeReport()

closeReport(): void

Fires the report-closed event, which will trigger any report-closed event listeners.

Returns

void


createReport()

createReport(): void

Fires the report-created event, which will trigger any report-created event listeners.

Returns

void


initialize()

initialize(): void

Initialize the SDK for testing. This will create the Broadcast Channels for both sending and receiving events. You must call this before attempting to use any other functions in this module.

Returns

void


respondToLastConfirmation()

respondToLastConfirmation(status): void

Fires the confirm-response event for the latest confirmation request. After responding to the latest confirmation request, that request is removed from the queue. The list functions as a stack.

Calling this with confirmed will trigger the onConfirm callback. Calling this with cancelled will trigger the onCancel callback (if provided).

warning

Because how the underlying Broadcast Channels pass messages (and how JavaScript handles events), you'll want to wrap this in a vi.waitFor:

await vi.waitFor(() => reporting.mocks.respondToLastConfirmation(...));
danger

Calling this without firing a confirm-response event first will result in an error.

Parameters

ParameterTypeDescription
status"confirmed" | "cancelled"Whether the "test user" has either confirmed or cancelled the confirmation request.

Returns

void


updateReport()

updateReport(reportContent): void

Fires the report-updated event, which will trigger any report-updated event listeners.

Parameters

ParameterTypeDescription
reportContentstringThe textual representation of the report.

Returns

void