inspectHandler
function in meocord/testing Since 4.1.0
inspectHandler<C extends new (...args: any[]) => unknown>(
controller: C,
methodName: keyof InstanceType<C> & string,
options?: InspectHandlerOptions,
): HandlerInspectionReports what runs when a handler is dispatched, and the metadata declared on it, without running anything.
Use it to check that decorators set a handler up as intended: its guards with their params, its interceptors,
filters and cooldowns, in the order dispatch applies them. To check what a handler does, run it with
TestingModule.invoke.
Parameters
| Name | Type | Description |
|---|---|---|
controller | C | The controller class declaring the handler. |
methodName | (keyof InstanceType<C>) & string | The handler method's name. |
options? | InspectHandlerOptions |
|
options.app? | new (...args: any[]) => unknown | The |
Returns
HandlerInspectionThe handler's stages in order, its message pattern, and readers for its metadata.
Examples
import { expect } from 'vitest'
@Controller()
@UseGuard(StaffGuard)
class ModerationController {
@Command('ban', CommandType.SLASH)
@UseGuard({ provide: ChannelGuard, params: { channelIds: ['123456789012345678'] } })
async ban(interaction: ChatInputCommandInteraction) {
await respond(interaction).send('Banned.')
}
}
const { guards } = inspectHandler(ModerationController, 'ban')
expect(guards).toEqual([StaffGuard, { provide: ChannelGuard, params: { channelIds: ['123456789012345678'] } }])