TestFlow class

Support class for TestAdapter that allows for the simple construction of a sequence of tests.

Remarks

Calling adapter.send() or adapter.test() will create a new test flow which you can chain together additional tests using a fluent syntax.

const { TestAdapter } = require('botbuilder');

const adapter = new TestAdapter(async (context) => {
   if (context.text === 'hi') {
      await context.sendActivity(`Hello World`);
   } else if (context.text === 'bye') {
      await context.sendActivity(`Goodbye`);
   }
});

adapter.test(`hi`, `Hello World`)
       .test(`bye`, `Goodbye`)
       .then(() => done());

Properties

previous

Methods

assertNoReply(string, number)

Generates an assertion that the turn processing logic did not generate a reply from the bot, as expected.

assertReply(string | Partial<Activity> | TestActivityInspector, string, number)

Generates an assertion if the bots response doesn't match the expected text/activity.

assertReplyOneOf(string[], string, number)

Generates an assertion if the bots response is not one of the candidate strings.

catch((reason: any) => void)

Adds a catch() clause to the tests promise chain.

delay(number)

Inserts a delay before continuing.

finally(() => void)

Adds a finally clause. Note that you can't keep chaining afterwards.

send(string | Partial<Activity>)

Sends something to the bot.

sendConversationUpdate()

Creates a conversation update activity and process the activity.

startTest()

Start the test sequence, returning a promise to await.

test(string | Partial<Activity>, string | Partial<Activity> | (activity: Partial<Activity>, description?: string) => void, string, number)

Send something to the bot and expects the bot to return with a given reply. This is simply a wrapper around calls to send() and assertReply(). This is such a common pattern that a helper is provided.

then(() => void, (err: any) => void)

Adds a then() step to the tests promise chain.

Property Details

previous

previous: Promise<void>

Property Value

Promise<void>

Method Details

assertNoReply(string, number)

Generates an assertion that the turn processing logic did not generate a reply from the bot, as expected.

function assertNoReply(description?: string, timeout?: number): TestFlow

Parameters

description

string

(Optional) Description of the test case. If not provided one will be generated.

timeout

number

(Optional) number of milliseconds to wait for a response from bot. Defaults to a value of 3000.

Returns

A new TestFlow object that appends this exchange to the modeled exchange.

assertReply(string | Partial<Activity> | TestActivityInspector, string, number)

Generates an assertion if the bots response doesn't match the expected text/activity.

function assertReply(expected: string | Partial<Activity> | TestActivityInspector, description?: string, timeout?: number): TestFlow

Parameters

expected

string | Partial<Activity> | TestActivityInspector

Expected text or activity from the bot. Can be a callback to inspect the response using custom logic.

description

string

(Optional) Description of the test case. If not provided one will be generated.

timeout

number

(Optional) number of milliseconds to wait for a response from bot. Defaults to a value of 3000.

Returns

A new TestFlow object that appends this exchange to the modeled exchange.

assertReplyOneOf(string[], string, number)

Generates an assertion if the bots response is not one of the candidate strings.

function assertReplyOneOf(candidates: string[], description?: string, timeout?: number): TestFlow

Parameters

candidates

string[]

List of candidate responses.

description

string

(Optional) Description of the test case. If not provided one will be generated.

timeout

number

(Optional) number of milliseconds to wait for a response from bot. Defaults to a value of 3000.

Returns

A new TestFlow object that appends this exchange to the modeled exchange.

catch((reason: any) => void)

Adds a catch() clause to the tests promise chain.

function catch(onRejected?: (reason: any) => void): TestFlow

Parameters

onRejected

(reason: any) => void

Code to run if the test has thrown an error.

Returns

A new TestFlow object that appends this exchange to the modeled exchange.

delay(number)

Inserts a delay before continuing.

function delay(ms: number): TestFlow

Parameters

ms

number

ms to wait.

Returns

A new TestFlow object that appends this exchange to the modeled exchange.

finally(() => void)

Adds a finally clause. Note that you can't keep chaining afterwards.

function finally(onFinally: () => void): Promise<void>

Parameters

onFinally

() => void

Code to run after the test chain.

Returns

Promise<void>

A promise representing the async operation.

send(string | Partial<Activity>)

Sends something to the bot.

function send(userSays: string | Partial<Activity>): TestFlow

Parameters

userSays

string | Partial<Activity>

Text or activity simulating user input.

Returns

A new TestFlow object that appends this exchange to the modeled exchange.

sendConversationUpdate()

Creates a conversation update activity and process the activity.

function sendConversationUpdate(): TestFlow

Returns

A new TestFlow object.

startTest()

Start the test sequence, returning a promise to await.

function startTest(): Promise<void>

Returns

Promise<void>

A promise representing the async operation.

test(string | Partial<Activity>, string | Partial<Activity> | (activity: Partial<Activity>, description?: string) => void, string, number)

Send something to the bot and expects the bot to return with a given reply. This is simply a wrapper around calls to send() and assertReply(). This is such a common pattern that a helper is provided.

function test(userSays: string | Partial<Activity>, expected: string | Partial<Activity> | (activity: Partial<Activity>, description?: string) => void, description?: string, timeout?: number): TestFlow

Parameters

userSays

string | Partial<Activity>

Text or activity simulating user input.

expected

string | Partial<Activity> | (activity: Partial<Activity>, description?: string) => void

Expected text or activity of the reply sent by the bot.

description

string

(Optional) Description of the test case. If not provided one will be generated.

timeout

number

(Optional) number of milliseconds to wait for a response from bot. Defaults to a value of 3000.

Returns

A new TestFlow object that appends this exchange to the modeled exchange.

then(() => void, (err: any) => void)

Adds a then() step to the tests promise chain.

function then(onFulfilled?: () => void, onRejected?: (err: any) => void): TestFlow

Parameters

onFulfilled

() => void

Code to run if the test is currently passing.

onRejected

(err: any) => void

Code to run if the test has thrown an error.

Returns

A new TestFlow object that appends this exchange to the modeled exchange.