createMockChannel
function in meocord/testing Since 4.0.0
createMockChannel<T extends BaseChannel>(
Class: InteractionClass<T>,
props?: MockProps<T>,
): DeepMocked<ChannelOf<T>>Creates a mock channel of the given class, such as TextChannel, ThreadChannel or DMChannel.
Use it for a channel a handler reads or posts to, such as one it fetches messages from or opens a thread in.
Parameters
| Name | Type | Since |
|---|---|---|
Class | InteractionClass<T> | |
The discord.js channel class to mock. | ||
props? | MockProps<T> | 4.1.0 |
Values for the channel's properties, such as its | ||
Returns
DeepMocked<ChannelOf<T>>Examples
import { expect } from 'vitest'
const thread = createMockChannel(ThreadChannel)
await thread.members.add('111111111111111111')
expect(thread.members.add).toHaveBeenCalledWith('111111111111111111')