Skip to content
GitHub

createMockClient

function in meocord/testing Since 4.0.0

createMockClient(): DeepMocked<Client<true>>

Creates a mock Client, with users, channels, guilds and application.commands ready to stub.

Use it when code under test reaches the client, such as to DM a user or fetch a channel, or to address messages to the bot. A mock message or interaction built without one gets a client of its own.

Returns

DeepMocked<Client<true>>

Examples

TypeScript
import { expect } from 'vitest'

const client = createMockClient()
const botId = client.user.id
const message = createMockMessage({ content: `<@${botId}> help`, client })
expect(message.mentions.users.has(botId)).toBe(true)