> ## Documentation Index
> Fetch the complete documentation index at: https://botmesh.afaya.com.co/llms.txt
> Use this file to discover all available pages before exploring further.

# createTestBot()

> Function exported by @botmesh/core/testing.

## Call Signature

```ts theme={null}
function createTestBot(config?, options?): Promise<TestBot>;
```

Defined in: [testing/createTestBot.ts:90](https://github.com/andresayac/botmesh/blob/main/packages/core/src/testing/createTestBot.ts#L90)

Starts a [Bot](https://botmesh.afaya.com.co/api/core/classes/Bot.md) on a [MockProvider](https://botmesh.afaya.com.co/api/core/testing/classes/MockProvider.md): no network and no phone. Resolves to
the bot, the provider and chat helpers that send inbound messages and check the replies.
`options.chaos` wraps the provider in a [ChaosProvider](https://botmesh.afaya.com.co/api/core/testing/classes/ChaosProvider.md).

### Parameters

| Parameter | Type |
| - | - |
| `config?` | `Omit`\<[`BotConfig`](https://botmesh.afaya.com.co/api/core/interfaces/BotConfig), `"provider"`> |
| `options?` | [`CreateTestBotOptions`](https://botmesh.afaya.com.co/api/core/testing/interfaces/CreateTestBotOptions) & `object` |

### Returns

`Promise`\<[`TestBot`](https://botmesh.afaya.com.co/api/core/testing/interfaces/TestBot)>

### Example

```ts theme={null}
import { createTestBot } from '@botmesh/core/testing'

const { bot, chat } = await createTestBot()
bot.when('hi', (ctx) => ctx.reply('Hello!'))

await chat.send('hi')
await chat.expectReply('Hello!')
await bot.stop()
```

## Call Signature

```ts theme={null}
function createTestBot(config, options): Promise<TestBot & object>;
```

Defined in: [testing/createTestBot.ts:91](https://github.com/andresayac/botmesh/blob/main/packages/core/src/testing/createTestBot.ts#L91)

Starts a [Bot](https://botmesh.afaya.com.co/api/core/classes/Bot.md) on a [MockProvider](https://botmesh.afaya.com.co/api/core/testing/classes/MockProvider.md): no network and no phone. Resolves to
the bot, the provider and chat helpers that send inbound messages and check the replies.
`options.chaos` wraps the provider in a [ChaosProvider](https://botmesh.afaya.com.co/api/core/testing/classes/ChaosProvider.md).

### Parameters

| Parameter | Type |
| - | - |
| `config` | \| `Omit`\<[`BotConfig`](https://botmesh.afaya.com.co/api/core/interfaces/BotConfig), `"provider"`> \| `undefined` |
| `options` | [`CreateTestBotOptions`](https://botmesh.afaya.com.co/api/core/testing/interfaces/CreateTestBotOptions) & `object` |

### Returns

`Promise`\<[`TestBot`](https://botmesh.afaya.com.co/api/core/testing/interfaces/TestBot) & `object`>

### Example

```ts theme={null}
import { createTestBot } from '@botmesh/core/testing'

const { bot, chat } = await createTestBot()
bot.when('hi', (ctx) => ctx.reply('Hello!'))

await chat.send('hi')
await chat.expectReply('Hello!')
await bot.stop()
```

## Call Signature

```ts theme={null}
function createTestBot(factory, options?): Promise<TestBot>;
```

Defined in: [testing/createTestBot.ts:111](https://github.com/andresayac/botmesh/blob/main/packages/core/src/testing/createTestBot.ts#L111)

Test the bot a defineBot factory builds: the factory is called with the
[MockProvider](https://botmesh.afaya.com.co/api/core/testing/classes/MockProvider.md) (or its chaos wrapper) and the bot it returns is started.

### Parameters

| Parameter | Type |
| - | - |
| `factory` | [`BotFactory`](https://botmesh.afaya.com.co/api/core/type-aliases/BotFactory) |
| `options?` | [`CreateTestBotOptions`](https://botmesh.afaya.com.co/api/core/testing/interfaces/CreateTestBotOptions) & `object` |

### Returns

`Promise`\<[`TestBot`](https://botmesh.afaya.com.co/api/core/testing/interfaces/TestBot)>

### Example

```ts theme={null}
import createBot from '../src/bot.js'

const { bot, chat } = await createTestBot(createBot)
await chat.send('hola')
await chat.expectReply(/Hola/)
await bot.stop()
```

### Throws

when the factory does not return a Bot built around the provider it was given.

## Call Signature

```ts theme={null}
function createTestBot(factory, options): Promise<TestBot & object>;
```

Defined in: [testing/createTestBot.ts:112](https://github.com/andresayac/botmesh/blob/main/packages/core/src/testing/createTestBot.ts#L112)

Starts a [Bot](https://botmesh.afaya.com.co/api/core/classes/Bot.md) on a [MockProvider](https://botmesh.afaya.com.co/api/core/testing/classes/MockProvider.md): no network and no phone. Resolves to
the bot, the provider and chat helpers that send inbound messages and check the replies.
`options.chaos` wraps the provider in a [ChaosProvider](https://botmesh.afaya.com.co/api/core/testing/classes/ChaosProvider.md).

### Parameters

| Parameter | Type |
| - | - |
| `factory` | [`BotFactory`](https://botmesh.afaya.com.co/api/core/type-aliases/BotFactory) |
| `options` | [`CreateTestBotOptions`](https://botmesh.afaya.com.co/api/core/testing/interfaces/CreateTestBotOptions) & `object` |

### Returns

`Promise`\<[`TestBot`](https://botmesh.afaya.com.co/api/core/testing/interfaces/TestBot) & `object`>

### Example

```ts theme={null}
import { createTestBot } from '@botmesh/core/testing'

const { bot, chat } = await createTestBot()
bot.when('hi', (ctx) => ctx.reply('Hello!'))

await chat.send('hi')
await chat.expectReply('Hello!')
await bot.stop()
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.