Testing
Inspection
ComponentCommandTypeThe command types routed by a
customIdpattern: buttons, select menus and modals.CooldownStoreSuiteFrameworkThe test framework
testCooldownStoreregisters its cases with: itsdescribe,itandexpect.createExecutionContextBuilds the
ExecutionContexta guard, interceptor or filter receives for one handler, to test it on its own.ExecutionContextOptionsWhat
createExecutionContextdescribes besides the handler.expectCompleteCatalogChecks that every locale translates every message, and throws listing each gap, locale by locale.
findRouteConflictsFinds component patterns that can match the same
customId, which MeoCord otherwise only warns about at startup.getResponseReports how an interaction was answered: where its answer stands, and every answer call it got, in order.
HandlerInspectionWhat runs for one handler, and the metadata declared on it, as
inspectHandlerreports it.InspectedCooldownOne
@Cooldownon a handler, with its defaults filled in, asinspectHandlerreports it.InspectedFilterA filter as
@UseFilterdeclares it: the class, or the class with its params.InspectedGuardA guard as
@UseGuarddeclares it: the class, or the class with its params.InspectedInterceptorAn interceptor as
@UseInterceptordeclares it: the class, or the class with its params.inspectHandlerReports what runs when a handler is dispatched, and the metadata declared on it, without running anything.
InspectHandlerOptionsWhat
inspectHandlerincludes besides the handler's own stages.MessageToResolveA message, as
resolveRoutetakes it.ResolvedRouteThe handler a component interaction or a message reaches, as
resolveRoutereports it.resolveRouteResolves which handler a component's
customIdor a message's content reaches, as dispatch routes it.ResponseReportHow an interaction was answered, as
getResponsereports it.RouteConflictTwo patterns of one component type that can both match a
customId, asfindRouteConflictsreports them.testCooldownStoreChecks that a
CooldownStorecounts calls asMemoryCooldownStoredoes, as a suite of test cases.
Mocks
ChatInputOptionsThe options of a mock slash command, as
createChatInputOptionstakes them: each value by its option's name.clearAllMocksClears the calls every mock from
meocord/testinghas recorded, keeping what each was told to do.createChatInputOptionsBuilds a slash command's options from a plain record, found by name as the real options resolver finds them.
createDiscordErrorCreates the error discord.js throws for a failed Discord API call, for a mock to reject with.
createMockCreates a mock of any type, with no class needed, for service doubles and interfaces.
createMockChannelCreates a mock channel of the given class, such as
TextChannel,ThreadChannelorDMChannel.createMockClientCreates a mock
Client, withusers,channels,guildsandapplication.commandsready to stub.createMockFnCreates a mock function that jest's and Vitest's
expectboth read.createMockGuildCreates a mock
Guild, with themembers,channels,rolesandbansmanagers ready to stub.createMockInteractionCreates a mock instance of a discord.js class, such as an interaction, keeping its prototype so
instanceofholds.createMockMemberCreates a mock
GuildMember: a user in a server, with the roles given.createMockMessageCreates a mock
Messagethat tracks whether it has been deleted.createMockThemeMakes a whole theme for a test: MeoCord's defaults with
overridesmerged over them, frozen.createMockUserCreates a mock
User: a person, not a bot, with an id of its own.createModalFieldsBuilds the
fieldsof a submitted form, as discord.js does when a user submits one.DeepMockedA mock of
T: every method a mock function, and every nested object mocked in turn, five levels deep, including a discord.js structure that may be absent, such as a message'smember, when it is present.isMockFunctionTells whether a value is a mock function: one from
meocord/testing,jest.fn()orvi.fn().MockA mock function, as jest's
Mockand Vitest'sMockname it: the same type asMockedFunction.MockedFunctionA mock function with the signature of
T, and the mock API ofMockInstance.MockGuildOverridesWhat
createMockGuildputs in the guild's caches, as the gateway would have filled them.MockInstanceThe mock API of a mock function: what it has recorded, and the methods that change what it does.
MockMemberOverridesWhat
createMockMemberbuilds a member with.MockMessageOverridesWhat
createMockMessagebuilds a message with.MockPropsProperty values a mock factory sets as it builds the mock.
MockResultOne call's outcome, as a mock function records it: the value it returned, or the error it threw.
MockStateWhat a mock function has recorded: each call's arguments, outcome and
this, in order.resetAllMocksClears every mock from
meocord/testing, and puts each back to the implementation it was created with.withThemeRuns
fnwiththemeas the theme of the call, as a handler's call runs.
Module
DispatchedCallWhat
TestingModule.dispatchdid with an interaction, a message or a reaction.DispatchedHandlerOne handler
TestingModule.dispatchran, and how its call ended.EmitResultHow an event sent with
TestingModule.emitwas handled.FromAppOptionsWhat a test changes of the app
MeoCordTestingModule.fromAppbuilds.HandlerNameThe names of a class's instance methods, as
TestingModule.invoketakes them.InvocationResultHow a call made with
TestingModule.invokeended.MeoCordTestingModuleBuilds testing modules: the classes a test needs, in a container of their own, with no Discord connection.
TestingModuleA compiled testing module, which runs handlers as the bot does and resolves the classes it built.
TestingModuleBuilderBuilds a testing module, with stand-ins for the providers, stages and theme a test replaces.
TestingModuleInitOptionsHow
TestingModule.initprepares the module.TestingModuleOptionsWhat a testing module is built from: the classes a test needs, and the app whose global stages apply.