resolveRoute
function in meocord/testing Since 4.0.0
resolveRoute(
app: ControllerClass,
input: { type: ComponentCommandType; customId: string } | MessageToResolve,
): ResolvedRoute | undefinedResolves which handler a component's customId or a message's content reaches, as dispatch routes it.
Use it to check routing alone, in a plain unit test: it reads decorator metadata, with no client, config or
container, and runs no guard. To run the handler it reaches, use TestingModule.dispatch.
Parameters
| Name | Type | Since | Description |
|---|---|---|---|
app | ControllerClass | The application class decorated with | |
input | | {
type: ComponentCommandType
customId: string
}
| MessageToResolve | 4.1.0 | The component type and its |
Returns
ResolvedRoute | undefinedThe handler that runs, with the params it captures, or undefined when no route handles the input.
Throws
TypeError for a message to an app whose prefix is a function, when no
prefixis given.
Examples
import { expect } from 'vitest'
@Controller()
class ProfileController {
@Command('profile/{uid}', CommandType.BUTTON)
async show(interaction: ButtonInteraction, { uid }: { uid: string }) {
await respond(interaction).send(`Profile ${uid}`)
}
}
@MeoCord({ controllers: [ProfileController], clientOptions: { intents: [] } })
class App {}
const route = resolveRoute(App, { type: CommandType.BUTTON, customId: 'profile/8000' })
expect([route?.handler, route?.params]).toEqual([ProfileController.prototype.show, { uid: '8000' }])