Edit

Share via


DialogTestClient class

A client for testing dialogs in isolation.

Constructors

DialogTestClient(string, Dialog, unknown, Middleware[], ConversationState)

Creates a DialogTestClient to test a Dialog without having to create a full-fledged adapter.

let client = new DialogTestClient('test', MY_DIALOG, MY_OPTIONS);
let reply = await client.sendActivity('first message');
assert.strictEqual(reply.text, 'first reply', 'reply failed');
DialogTestClient(TestAdapter, Dialog, unknown, Middleware[], ConversationState)

Creates a DialogTestClient to test a Dialog without having to create a full-fledged adapter.

let client = new DialogTestClient(MY_DIALOG, MY_OPTIONS);
let reply = await client.sendActivity('first message');
assert.strictEqual(reply.text, 'first reply', 'reply failed');

Properties

conversationState

A ConversationState instance for the current test client.

dialogContext

Gets a reference for the DialogContext.

dialogTurnResult

A DialogTurnResult instance with the result of the last turn.

Methods

getNextReply()

Get the next reply waiting to be delivered (if one exists)

sendActivity(Partial<Activity> | string)

Send an activity into the dialog.

await DialogTest.send('hello').assertReply('hello yourself').startTest();

Constructor Details

DialogTestClient(string, Dialog, unknown, Middleware[], ConversationState)

Creates a DialogTestClient to test a Dialog without having to create a full-fledged adapter.

let client = new DialogTestClient('test', MY_DIALOG, MY_OPTIONS);
let reply = await client.sendActivity('first message');
assert.strictEqual(reply.text, 'first reply', 'reply failed');
new DialogTestClient(channelId: string, targetDialog: Dialog, initialDialogOptions?: unknown, middlewares?: Middleware[], conversationState?: ConversationState)

Parameters

channelId

string

The channelId to be used for the test. Use 'emulator' or 'test' if you are uncertain of the channel you are targeting. Otherwise, it is recommended that you use the id for the channel(s) your bot will be using and write a test case for each channel.

targetDialog

Dialog

The Dialog to be tested. This will be the root dialog for the test client.

initialDialogOptions

unknown

Optional. Additional argument(s) to pass to the Dialog being started.

middlewares

Middleware[]

Optional. A Middleware list to be added to the test adapter.

conversationState

ConversationState

Optional. A ConversationState instance to use in the test client.

DialogTestClient(TestAdapter, Dialog, unknown, Middleware[], ConversationState)

Creates a DialogTestClient to test a Dialog without having to create a full-fledged adapter.

let client = new DialogTestClient(MY_DIALOG, MY_OPTIONS);
let reply = await client.sendActivity('first message');
assert.strictEqual(reply.text, 'first reply', 'reply failed');
new DialogTestClient(testAdapter: TestAdapter, targetDialog: Dialog, initialDialogOptions?: unknown, middlewares?: Middleware[], conversationState?: ConversationState)

Parameters

testAdapter

TestAdapter

The TestAdapter to use.

targetDialog

Dialog

The Dialog to be tested. This will be the root dialog for the test client.

initialDialogOptions

unknown

Optional. Additional argument(s) to pass to the Dialog being started.

middlewares

Middleware[]

Optional. A Middleware list to be added to the test adapter.

conversationState

ConversationState

Optional. A ConversationState instance to use in the test client.

Property Details

conversationState

A ConversationState instance for the current test client.

conversationState: ConversationState

Property Value

ConversationState

dialogContext

Gets a reference for the DialogContext.

DialogContext dialogContext

Property Value

DialogContext

the dialog context

Remarks

This property will be null until at least one activity is sent to DialogTestClient.

dialogTurnResult

A DialogTurnResult instance with the result of the last turn.

dialogTurnResult: DialogTurnResult

Property Value

DialogTurnResult

Method Details

getNextReply()

Get the next reply waiting to be delivered (if one exists)

function getNextReply(): Partial<Activity>

Returns

Partial<Activity>

the next reply

sendActivity(Partial<Activity> | string)

Send an activity into the dialog.

await DialogTest.send('hello').assertReply('hello yourself').startTest();
function sendActivity(activity: Partial<Activity> | string): Promise<any>

Parameters

activity

Partial<Activity> | string

an activity potentially with text

Returns

Promise<any>

a TestFlow that can be used to assert replies etc