Skip to content
GitHub

Testing helpers at a glance

Every helper meocord/testing exports, how it is called and what it does.

Inspection

HelperWhat it does
createExecutionContext(controller, methodName, options?)

Builds the ExecutionContext a guard, interceptor or filter receives for one handler, to test it on its own.

expectCompleteCatalog(translator, options?)

Checks that every locale translates every message, and throws listing each gap, locale by locale.

findRouteConflicts(app)

Finds component patterns that rank equally and can match the same customId, which MeoCord otherwise only warns about at startup.

getResponse(interaction)

Reports how an interaction was answered: where its answer stands, and every answer call it got, in order.

inspectHandler(controller, methodName, options?)

Reports what runs when a handler is dispatched, and the metadata declared on it, without running anything.

resolveRoute(app, input)

Resolves which handler a component's customId or a message's content reaches, as dispatch routes it.

testCooldownStore(name, factory, framework)

Checks that a CooldownStore counts calls as MemoryCooldownStore does, as a suite of test cases.

Mocks

HelperWhat it does
clearAllMocks()

Clears the calls every mock from meocord/testing has recorded, keeping what each was told to do.

createChatInputOptions(opts?)

Builds a slash command's options from a plain record, found by name as the real options resolver finds them.

createDiscordError(code, message?)

Creates the error discord.js throws for a failed Discord API call, for a mock to reject with.

createMock(props?)

Creates a mock of any type, with no class needed, for service doubles and interfaces.

createMockChannel(Class, props?)

Creates a mock channel of the given class, such as TextChannel, ThreadChannel or DMChannel.

createMockClient()

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

createMockFn(impl?)

Creates a mock function that jest's and Vitest's expect both read.

createMockGuild(overrides?)

Creates a mock Guild, with the members, channels, roles and bans managers ready to stub.

createMockInteraction(Class, props?) createMockInteraction(Class, props)

Creates a mock instance of a discord.js class, such as an interaction, keeping its prototype so instanceof holds.

createMockMember(overrides?)

Creates a mock GuildMember: a user in a server, with the roles given.

createMockMessage(overrides?)

Creates a mock Message that tracks whether it has been deleted.

createMockRawMember(overrides?)

Creates the member Discord sends with an interaction from a server the bot isn't in, as discord.js keeps it.

createMockTheme(...overrides)

Makes a whole theme for a test: MeoCord's defaults with overrides merged over them, frozen.

createMockUser

Creates a mock User: a person, not a bot, with an id of its own.

createModalFields(values)

Builds the fields of a submitted form, as discord.js does when a user submits one.

isMockFunction(fn)

Tells whether a value is a mock function: one from meocord/testing, jest.fn() or vi.fn().

resetAllMocks()

Clears every mock from meocord/testing, and puts each back to the implementation it was created with.

useMockFn(factory)

Makes every mock meocord/testing creates with the test runner's own mock function, such as Vitest's vi.fn.

useStrictMocks()

Has every mock from meocord/testing compute the values discord.js computes, where it reads a placeholder otherwise.

withTheme(theme, fn)

Runs fn with theme as the theme of the call, as a handler's call runs.

Module

HelperWhat it does
reportAllStartupErrors()

Has decorators keep the startup errors they find, as a bot built with startupErrors: 'all' does, so a testing module reports every one at once.