Packages@robojs/mock
createTestUtils()
Function: createTestUtils()
Call Signature
function createTestUtils(sessionOrId): TestUtilsCreate test utilities for a session.
Accepts either the internal Session instance or a sessionId string.
When given a string, the session is resolved from the in-process session manager
(requires the mock server to be running in the same process).
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionOrId | Session | The session instance or session ID string |
Returns
Object with users and interactions helpers
Example
import { startMockRobo, createTestUtils } from '@robojs/mock/testing'
const bot = await startMockRobo({ name: 'test' })
const { users, interactions } = createTestUtils(bot.sessionId)
// Create test users
const [alice, bob] = users.createMany(['Alice', 'Bob'])
// Simulate a conversation
await interactions.conversation(channelId, [
{ user: 'Alice', content: 'Hello!' },
{ user: 'Bob', content: 'Hi there!' }
])
// Act as a specific user
await users.as(alice, async () => {
// Do something as Alice
})Call Signature
function createTestUtils(sessionOrId): TestUtilsCreate test utilities for a session.
Accepts either the internal Session instance or a sessionId string.
When given a string, the session is resolved from the in-process session manager
(requires the mock server to be running in the same process).
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionOrId | string | The session instance or session ID string |
Returns
Object with users and interactions helpers
Example
import { startMockRobo, createTestUtils } from '@robojs/mock/testing'
const bot = await startMockRobo({ name: 'test' })
const { users, interactions } = createTestUtils(bot.sessionId)
// Create test users
const [alice, bob] = users.createMany(['Alice', 'Bob'])
// Simulate a conversation
await interactions.conversation(channelId, [
{ user: 'Alice', content: 'Hello!' },
{ user: 'Bob', content: 'Hi there!' }
])
// Act as a specific user
await users.as(alice, async () => {
// Do something as Alice
})