createChatInputOptions
function in meocord/testing Since 4.0.0
createChatInputOptions<Cached extends CacheType = any>(
opts?: ChatInputOptions,
): DeepMocked<CommandInteractionOptionResolver<Cached>>Builds a slash command's options from a plain record, found by name as the real options resolver finds them.
Use it for the options of a mock ChatInputCommandInteraction, including an autocomplete's focused option. The
options are nested under the subcommand and group as Discord sends them, so the handler's params build as in the bot.
Parameters
| Name | Type | Description |
|---|---|---|
opts? | ChatInputOptions | Each option's value by its name, with the |
opts.subcommandGroup? | string | null | The subcommand group the command was used through. |
opts.subcommand? | string | null | The subcommand the command was used through. |
opts.focused? | string | null | The option the user is currently typing, for autocomplete interactions. |
Returns
DeepMocked<CommandInteractionOptionResolver<Cached>>Examples
import { expect } from 'vitest'
const interaction = createMockInteraction(ChatInputCommandInteraction, {
commandName: 'settings',
options: createChatInputOptions({ subcommandGroup: 'notify', subcommand: 'email', address: 'ada@example.com' }),
})
expect(interaction.options.getSubcommand()).toBe('email')
expect(interaction.options.getString('address')).toBe('ada@example.com')